@cnc-tools/storm 0.10.0 → 0.11.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 +17 -9
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-YF3ICDBY.js → chunk-3ZZVZPMG.js} +1 -1
- package/dist/chunks/{chunk-JQ2HK4RN.js → chunk-4EU4AH7E.js} +141 -6
- package/dist/chunks/{chunk-ZJ2USLAT.js → chunk-4PRAB24Y.js} +2 -22
- package/dist/chunks/chunk-AMTYHUYB.js +257 -0
- package/dist/chunks/{chunk-WF4KJ7YG.js → chunk-ETCZ6WP7.js} +1 -1
- package/dist/chunks/chunk-FVMQKYTT.js +10 -0
- package/dist/chunks/{chunk-XHJGHJBW.js → chunk-GRMD7G4J.js} +33 -275
- package/dist/chunks/chunk-ICB4BZJX.js +22 -0
- package/dist/chunks/{chunk-AGWW3HDT.js → chunk-KR7WIYLG.js} +1826 -2201
- package/dist/chunks/{chunk-OVXD7GES.js → chunk-L4ZPMSKQ.js} +4 -37
- package/dist/chunks/chunk-NPPJ57W7.js +569 -0
- package/dist/chunks/{chunk-VJQLMGOH.js → chunk-O4BUT7BE.js} +361 -1716
- package/dist/chunks/chunk-OJOKQRM6.js +1457 -0
- package/dist/chunks/chunk-SLNKW4ZM.js +40 -0
- package/dist/chunks/{chunk-AKKNF3WZ.js → chunk-TRFEAYNC.js} +277 -348
- package/dist/chunks/chunk-VZZTHCBW.js +93 -0
- package/dist/chunks/chunk-WNIQA5J6.js +19 -0
- package/dist/chunks/chunk-WSIF7SR6.js +10 -0
- package/dist/chunks/{live-app-RIJM3QFD.js → live-app-LOGYUBKB.js} +52 -7
- package/dist/commands/exec/cleanup.d.ts +3 -3
- package/dist/commands/exec/cleanup.js +6 -2
- package/dist/commands/exec/command.d.ts +3 -3
- package/dist/commands/exec/command.js +17 -10
- package/dist/commands/exec/job-summary.d.ts +1 -1
- package/dist/commands/exec/job-summary.js +1 -1
- package/dist/commands/exec/live-view.js +5 -5
- package/dist/commands/exec/mint-failed.js +1 -1
- package/dist/commands/exec/outcomes.d.ts +2 -2
- package/dist/commands/exec/outcomes.js +7 -8
- package/dist/commands/exec/plan-run.d.ts +3 -5
- package/dist/commands/exec/progress.d.ts +3 -3
- package/dist/commands/exec/progress.js +6 -6
- package/dist/commands/exec/resource-refusals.d.ts +1 -1
- package/dist/commands/exec/resource-refusals.js +1 -1
- package/dist/commands/exec/run-command.d.ts +14 -9
- package/dist/commands/exec/run-command.js +91 -202
- package/dist/commands/exec/run-metadata.d.ts +2 -2
- package/dist/commands/exec/run-metadata.js +3 -3
- package/dist/commands/exec/test-plan.d.ts +1 -35
- package/dist/commands/exec/test-plan.js +4 -24
- package/dist/commands/exec/view.js +3 -3
- package/dist/commands/exec/waterfall.d.ts +3 -1
- package/dist/commands/exec/waterfall.js +18 -1
- package/dist/commands/runs/facts.d.ts +2 -1
- package/dist/commands/runs/facts.js +1 -1
- package/dist/commands/runs/list/command.js +10 -9
- package/dist/commands/runs/logs/command.js +14 -12
- package/dist/commands/runs/past-run.d.ts +3 -27
- package/dist/commands/runs/past-run.js +3 -37
- package/dist/commands/runs/show/command.js +24 -21
- package/dist/commands/runs/show/outcomes.js +2 -2
- package/dist/commands/vitest/command.d.ts +3 -3
- package/dist/commands/vitest/command.js +24 -17
- package/dist/commands/vitest/outcomes.d.ts +1 -1
- package/dist/commands/vitest/outcomes.js +1 -1
- package/dist/config/credential-resolver.d.ts +6 -3
- package/dist/config/credential-resolver.js +6 -5
- package/dist/context.d.ts +27 -9
- package/dist/context.js +19 -8
- package/dist/core/before-run.d.ts +5 -4
- package/dist/core/before-run.js +6 -6
- package/dist/core/definition-lookup.d.ts +22 -0
- package/dist/core/definition-lookup.js +34 -0
- package/dist/core/events.d.ts +5 -19
- package/dist/core/gateways.d.ts +22 -162
- package/dist/core/index.d.ts +10 -11
- package/dist/core/index.js +9 -11
- package/dist/core/launcher-supplies.js +2 -2
- package/dist/core/live/terminal-command-gateway.d.ts +8 -0
- package/dist/core/live/terminal-command-gateway.js +49 -0
- package/dist/core/presentations.d.ts +4 -3
- package/dist/core/presentations.js +4 -5
- package/dist/core/resource-registry.d.ts +35 -51
- package/dist/core/resource-registry.js +27 -54
- package/dist/core/resource-reports.d.ts +37 -4
- package/dist/core/resource-reports.js +34 -5
- package/dist/core/resources.d.ts +4 -3
- package/dist/core/resources.js +2 -4
- package/dist/core/run-state.d.ts +1 -1
- package/dist/core/run-state.js +1 -1
- package/dist/core/run.d.ts +19 -37
- package/dist/core/run.js +59 -114
- package/dist/core/timeline.js +2 -1
- package/dist/credential/events.d.ts +20 -0
- package/dist/credential/events.js +4 -0
- package/dist/credential/index.d.ts +2 -1
- package/dist/credential/index.js +6 -5
- package/dist/credential/source.d.ts +38 -26
- package/dist/credential/source.js +25 -34
- package/dist/extension-commands.d.ts +12 -6
- package/dist/extension-commands.js +18 -11
- package/dist/extensions/story/command-tree.d.ts +6 -0
- package/dist/extensions/story/command-tree.js +21 -0
- package/dist/extensions/story/commands/app.d.ts +23 -0
- package/dist/extensions/story/commands/app.js +5 -0
- package/dist/extensions/story/commands/run/command.d.ts +211 -0
- package/dist/extensions/story/commands/run/command.js +259 -0
- package/dist/extensions/story/commands/run/metadata.d.ts +4 -0
- package/dist/extensions/story/commands/run/metadata.js +8 -0
- package/dist/extensions/story/commands/run/outcomes.d.ts +101 -0
- package/dist/extensions/story/commands/run/outcomes.js +73 -0
- package/dist/extensions/story/commands/tree.d.ts +2 -0
- package/dist/extensions/story/commands/tree.js +6 -0
- package/dist/extensions/story/extension.d.ts +2 -0
- package/dist/extensions/story/extension.js +8 -0
- package/dist/extensions/testserver/command-tree.d.ts +1 -1
- package/dist/extensions/testserver/command-tree.js +0 -1
- package/dist/extensions/testserver/commands/pool/create/command.js +14 -8
- package/dist/extensions/testserver/commands/pool/list/command.js +8 -4
- package/dist/extensions/testserver/vitest/config.d.ts +7 -5
- package/dist/extensions/testserver/vitest/config.js +7 -5
- package/dist/extensions/testserver/vitest/fixtures.d.ts +2 -0
- package/dist/extensions/testserver/vitest/fixtures.js +36 -5
- package/dist/extensions.d.ts +12 -21
- package/dist/extensions.js +22 -34
- package/dist/forward-sigterm.d.ts +8 -0
- package/dist/forward-sigterm.js +18 -0
- package/dist/launcher-resolvers/index.d.ts +1 -0
- package/dist/launcher-resolvers/index.js +2 -1
- package/dist/launcher-resolvers/local-services.d.ts +57 -0
- package/dist/launcher-resolvers/local-services.js +7 -0
- package/dist/live-app.js +2 -1
- package/dist/local-services.d.ts +19 -0
- package/dist/local-services.js +37 -0
- package/dist/run-directory/gateways.d.ts +167 -0
- package/dist/run-directory/gateways.js +2 -0
- package/dist/run-directory/index.d.ts +8 -0
- package/dist/run-directory/index.js +13 -0
- package/dist/run-directory/plan.d.ts +35 -0
- package/dist/run-directory/plan.js +24 -0
- package/dist/run-directory/reader.d.ts +70 -0
- package/dist/run-directory/reader.js +51 -0
- package/dist/run-directory/recording.d.ts +92 -0
- package/dist/run-directory/recording.js +85 -0
- package/dist/{commands/exec → run-directory}/run-collector.d.ts +9 -8
- package/dist/{commands/exec → run-directory}/run-collector.js +8 -10
- package/dist/{core → run-directory}/run-directory.d.ts +3 -3
- package/dist/{core → run-directory}/run-directory.js +2 -2
- package/dist/{commands/exec → run-directory}/run-record.d.ts +29 -7
- package/dist/{commands/exec → run-directory}/run-record.js +79 -5
- package/dist/{commands/exec → run-directory}/timeline-facts.d.ts +4 -8
- package/dist/{commands/exec → run-directory}/timeline-facts.js +8 -24
- package/dist/runner/events.d.ts +6 -5
- package/dist/runner/index.d.ts +13 -17
- package/dist/runner/index.js +10 -14
- package/dist/runner/prepare.d.ts +28 -6
- package/dist/runner/prepare.js +15 -9
- package/dist/runner/recipe.d.ts +14 -0
- package/dist/runner/recipe.js +12 -0
- package/dist/runner/scope.d.ts +18 -11
- package/dist/runner/scope.js +12 -10
- package/dist/runner/session.d.ts +100 -0
- package/dist/runner/session.js +109 -0
- package/dist/runner/snapshot-save.d.ts +3 -2
- package/dist/runner/snapshot-save.js +6 -5
- package/dist/sdk/extension/ci.d.ts +2 -0
- package/dist/sdk/extension/ci.js +6 -0
- package/dist/sdk/extension/commands.d.ts +11 -13
- package/dist/sdk/extension/commands.js +5 -5
- package/dist/sdk/extension/index.d.ts +1 -0
- package/dist/sdk/extension/index.js +1 -0
- package/dist/sdk/extension/lifecycle.d.ts +4 -3
- package/dist/sdk/extension/progress.js +2 -2
- package/dist/sdk/extension/resource.js +1 -1
- package/dist/story/align.d.ts +1 -1
- package/dist/story/align.js +1 -1
- package/dist/story/command-line.d.ts +6 -16
- package/dist/story/command-line.js +11 -23
- package/dist/story/errors.d.ts +1 -1
- package/dist/story/errors.js +1 -1
- package/dist/story/host.d.ts +1 -1
- package/dist/story/host.js +2 -2
- package/dist/story/index.d.ts +2 -2
- package/dist/story/index.js +4 -3
- package/dist/story/launch.d.ts +70 -0
- package/dist/story/launch.js +77 -0
- package/dist/story/report.d.ts +2 -2
- package/dist/story/report.js +3 -4
- package/dist/story/settle.d.ts +7 -7
- package/dist/story/settle.js +5 -5
- package/dist/story/start.d.ts +2 -2
- package/dist/vendor/testserver-sdk/container/container.d.ts +11 -6
- package/dist/vendor/testserver-sdk/container/container.js +38 -16
- package/dist/vendor/testserver-sdk/testserver/failure.d.ts +4 -3
- package/dist/vendor/testserver-sdk/testserver/failure.js +4 -3
- package/package.json +1 -1
- package/skills/overview.md +3 -0
- package/skills/read-run-output.md +2 -2
- package/dist/chunks/chunk-H2VCSNVU.js +0 -351
- package/dist/chunks/chunk-J6ZNYUDV.js +0 -21
- package/dist/core/mint.d.ts +0 -10
- package/dist/core/mint.js +0 -14
- package/dist/story/mode.d.ts +0 -17
- package/dist/story/mode.js +0 -21
- /package/dist/{core → run-directory}/live/run-directory-gateway.d.ts +0 -0
- /package/dist/{core → run-directory}/live/run-directory-gateway.js +0 -0
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CREATE_CONCURRENCY,
|
|
3
2
|
Credential,
|
|
4
3
|
NOT_COUNTED,
|
|
5
|
-
TESTSERVER_REPO,
|
|
6
|
-
buildMatch,
|
|
7
|
-
createFailureText,
|
|
8
|
-
createPooledSandbox,
|
|
9
4
|
defaultResourceKey,
|
|
10
|
-
defineResource,
|
|
11
|
-
describeCreateFailure,
|
|
12
|
-
describeCredentialFailure,
|
|
13
5
|
describeMintFailure,
|
|
14
|
-
describeTtl,
|
|
15
6
|
describeValue,
|
|
16
|
-
leaseUsable,
|
|
17
|
-
liveControlPlaneGateway,
|
|
18
|
-
liveHealthCheckGateway,
|
|
19
|
-
livePoolStoreGateway,
|
|
20
|
-
mayLeaveSandbox,
|
|
21
|
-
minTimeLeftMinutes,
|
|
22
|
-
minutesSince,
|
|
23
7
|
nonEmptyString,
|
|
24
8
|
optionKeyPath,
|
|
25
|
-
parseBuildReference,
|
|
26
|
-
releaseLeases,
|
|
27
|
-
resolveBuild,
|
|
28
|
-
resolvePrBuild,
|
|
29
9
|
resourceCall,
|
|
30
|
-
shortSha,
|
|
31
|
-
testserverPoolRules,
|
|
32
10
|
tokenRequestFailureFacts,
|
|
33
|
-
tokenRequestFailureShape
|
|
34
|
-
|
|
35
|
-
unavailablePoolStoreGateway
|
|
36
|
-
} from "./chunk-XHJGHJBW.js";
|
|
11
|
+
tokenRequestFailureShape
|
|
12
|
+
} from "./chunk-AMTYHUYB.js";
|
|
37
13
|
import {
|
|
38
14
|
defineErrors,
|
|
39
15
|
refused
|
|
40
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-4PRAB24Y.js";
|
|
41
17
|
|
|
42
18
|
// src/runner/live/user.ts
|
|
43
19
|
import { userInfo } from "node:os";
|
|
@@ -49,46 +25,6 @@ function localUserName() {
|
|
|
49
25
|
}
|
|
50
26
|
}
|
|
51
27
|
|
|
52
|
-
// src/runner/base.ts
|
|
53
|
-
async function resolveBase(checkout, request2) {
|
|
54
|
-
const { repoRoot } = request2;
|
|
55
|
-
const refused2 = [];
|
|
56
|
-
let best;
|
|
57
|
-
for (const ref of request2.baseRefs) {
|
|
58
|
-
const candidate = await checkout.baseCandidate({ repoRoot, ref });
|
|
59
|
-
if (candidate.kind === "failed") return candidate;
|
|
60
|
-
if (candidate.kind === "missing-ref") {
|
|
61
|
-
refused2.push({ ref, reason: "missing" });
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (candidate.kind === "unrelated") {
|
|
65
|
-
refused2.push({ ref, reason: "unrelated" });
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (best === void 0) {
|
|
69
|
-
best = { base: candidate.base, ref };
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (candidate.base === best.base) continue;
|
|
73
|
-
const newer = await checkout.contains({ repoRoot, ancestor: best.base, descendant: candidate.base });
|
|
74
|
-
if (!newer.ok) return { kind: "failed", failure: newer.failure };
|
|
75
|
-
if (newer.value) best = { base: candidate.base, ref };
|
|
76
|
-
}
|
|
77
|
-
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
78
|
-
}
|
|
79
|
-
function baseStepContext(checkout, request2) {
|
|
80
|
-
const { repoRoot, base } = request2;
|
|
81
|
-
return {
|
|
82
|
-
base,
|
|
83
|
-
readBaseFile: async (path) => {
|
|
84
|
-
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
85
|
-
if (file.kind === "found") return file.text;
|
|
86
|
-
if (file.kind === "missing") throw new Error(`${path} doesn't exist at ${base.slice(0, 12)}`);
|
|
87
|
-
throw new Error(`can't read ${path} at ${base.slice(0, 12)}: ${file.failure.message}`);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
28
|
// src/runner/events.ts
|
|
93
29
|
function progressQueue(progress) {
|
|
94
30
|
let pending = Promise.resolve();
|
|
@@ -309,6 +245,46 @@ function createTarball(repoRoot, paths) {
|
|
|
309
245
|
// src/runner/snapshot-key.ts
|
|
310
246
|
import { createHash } from "node:crypto";
|
|
311
247
|
|
|
248
|
+
// src/runner/base.ts
|
|
249
|
+
async function resolveBase(checkout, request2) {
|
|
250
|
+
const { repoRoot } = request2;
|
|
251
|
+
const refused2 = [];
|
|
252
|
+
let best;
|
|
253
|
+
for (const ref of request2.baseRefs) {
|
|
254
|
+
const candidate = await checkout.baseCandidate({ repoRoot, ref });
|
|
255
|
+
if (candidate.kind === "failed") return candidate;
|
|
256
|
+
if (candidate.kind === "missing-ref") {
|
|
257
|
+
refused2.push({ ref, reason: "missing" });
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (candidate.kind === "unrelated") {
|
|
261
|
+
refused2.push({ ref, reason: "unrelated" });
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (best === void 0) {
|
|
265
|
+
best = { base: candidate.base, ref };
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (candidate.base === best.base) continue;
|
|
269
|
+
const newer = await checkout.contains({ repoRoot, ancestor: best.base, descendant: candidate.base });
|
|
270
|
+
if (!newer.ok) return { kind: "failed", failure: newer.failure };
|
|
271
|
+
if (newer.value) best = { base: candidate.base, ref };
|
|
272
|
+
}
|
|
273
|
+
return best === void 0 ? { kind: "no-base-ref", refs: refused2 } : { kind: "resolved", ...best };
|
|
274
|
+
}
|
|
275
|
+
function baseStepContext(checkout, request2) {
|
|
276
|
+
const { repoRoot, base } = request2;
|
|
277
|
+
return {
|
|
278
|
+
base,
|
|
279
|
+
readBaseFile: async (path) => {
|
|
280
|
+
const file = await checkout.readFileAt({ repoRoot, commit: base, path });
|
|
281
|
+
if (file.kind === "found") return file.text;
|
|
282
|
+
if (file.kind === "missing") throw new Error(`${path} doesn't exist at ${base.slice(0, 12)}`);
|
|
283
|
+
throw new Error(`can't read ${path} at ${base.slice(0, 12)}: ${file.failure.message}`);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
312
288
|
// src/time/duration.ts
|
|
313
289
|
var MIN_TTL_MINUTES = 10;
|
|
314
290
|
var MAX_TTL_MINUTES = 300;
|
|
@@ -407,10 +383,10 @@ var testEventSchema = z2.discriminatedUnion("kind", [
|
|
|
407
383
|
function testEventLine(event) {
|
|
408
384
|
return JSON.stringify(event);
|
|
409
385
|
}
|
|
410
|
-
function parseTestEvent(
|
|
386
|
+
function parseTestEvent(line) {
|
|
411
387
|
let json;
|
|
412
388
|
try {
|
|
413
|
-
json = JSON.parse(
|
|
389
|
+
json = JSON.parse(line);
|
|
414
390
|
} catch {
|
|
415
391
|
return void 0;
|
|
416
392
|
}
|
|
@@ -455,8 +431,8 @@ function rewritePaths(text, fromRoot, toRoot) {
|
|
|
455
431
|
function outputTail(limit = OUTPUT_TAIL_LINES) {
|
|
456
432
|
const kept = [];
|
|
457
433
|
return {
|
|
458
|
-
add(
|
|
459
|
-
kept.push(
|
|
434
|
+
add(line) {
|
|
435
|
+
kept.push(line);
|
|
460
436
|
if (kept.length > limit) kept.shift();
|
|
461
437
|
},
|
|
462
438
|
lines: () => [...kept]
|
|
@@ -484,9 +460,9 @@ async function runStep(context, request2, progress, signal) {
|
|
|
484
460
|
const tail = outputTail();
|
|
485
461
|
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
486
462
|
const emit = (stream, text) => {
|
|
487
|
-
for (const
|
|
488
|
-
tail.add(
|
|
489
|
-
queue.add({ kind: "step-output", phase, stream, line
|
|
463
|
+
for (const line of splitLines(text)) {
|
|
464
|
+
tail.add(line);
|
|
465
|
+
queue.add({ kind: "step-output", phase, stream, line });
|
|
490
466
|
}
|
|
491
467
|
};
|
|
492
468
|
const ran = await context.runnerSandboxes.runScript(
|
|
@@ -514,6 +490,9 @@ function sandboxStop(operation, failure) {
|
|
|
514
490
|
}
|
|
515
491
|
|
|
516
492
|
// src/runner/recipe.ts
|
|
493
|
+
function runStepTakesSecret(recipe) {
|
|
494
|
+
return recipe.run.install.secrets.length > 0 || recipe.run.build.secrets.length > 0;
|
|
495
|
+
}
|
|
517
496
|
var RECIPE_DEFAULTS = {
|
|
518
497
|
cwd: ".",
|
|
519
498
|
timeout: "60m",
|
|
@@ -531,6 +510,7 @@ var RECIPE_KEYS = /* @__PURE__ */ new Set([
|
|
|
531
510
|
"secrets",
|
|
532
511
|
"timeout",
|
|
533
512
|
"keepSandbox",
|
|
513
|
+
"saveSnapshot",
|
|
534
514
|
"baseRefs",
|
|
535
515
|
"region",
|
|
536
516
|
"runtime"
|
|
@@ -556,7 +536,7 @@ var RESERVED_SECRET_NAMES = /* @__PURE__ */ new Set([
|
|
|
556
536
|
var RESERVED_SECRET_PREFIXES = ["LD_", "DYLD_"];
|
|
557
537
|
function checkRecipe(value) {
|
|
558
538
|
const problems = [];
|
|
559
|
-
const report = (path,
|
|
539
|
+
const report = (path, problem) => problems.push({ path, problem });
|
|
560
540
|
if (!isRecord(value)) {
|
|
561
541
|
report([], `must be an object, not ${describeRecipeValue(value)}`);
|
|
562
542
|
return { ok: false, problems };
|
|
@@ -593,6 +573,9 @@ function checkRecipe(value) {
|
|
|
593
573
|
["keepSandbox"],
|
|
594
574
|
`must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`
|
|
595
575
|
);
|
|
576
|
+
const saveSnapshot = value["saveSnapshot"];
|
|
577
|
+
if (saveSnapshot !== void 0 && typeof saveSnapshot !== "boolean")
|
|
578
|
+
report(["saveSnapshot"], `must be true or false, not ${describeRecipeValue(saveSnapshot)}`);
|
|
596
579
|
const baseRefs = checkBaseRefs(value["baseRefs"], report);
|
|
597
580
|
const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
|
|
598
581
|
if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeRecipeValue(region)}`);
|
|
@@ -614,6 +597,7 @@ function checkRecipe(value) {
|
|
|
614
597
|
timeout,
|
|
615
598
|
timeoutMinutes,
|
|
616
599
|
keepSandboxMinutes,
|
|
600
|
+
...typeof saveSnapshot === "boolean" ? { saveSnapshot } : {},
|
|
617
601
|
baseRefs,
|
|
618
602
|
region,
|
|
619
603
|
runtime
|
|
@@ -816,7 +800,7 @@ async function resolveSteps(steps, context, declared) {
|
|
|
816
800
|
const problems = [];
|
|
817
801
|
const names = new Set(declared);
|
|
818
802
|
const checked = returned.map(
|
|
819
|
-
(step, index) => checkStep(step, [String(index)], names, (path,
|
|
803
|
+
(step, index) => checkStep(step, [String(index)], names, (path, problem) => problems.push({ path, problem }))
|
|
820
804
|
);
|
|
821
805
|
const first = problems[0];
|
|
822
806
|
if (first !== void 0)
|
|
@@ -1197,7 +1181,7 @@ function liveRunnerSandboxGateway() {
|
|
|
1197
1181
|
const holder = holding(sandbox);
|
|
1198
1182
|
holder.keeping = true;
|
|
1199
1183
|
await Promise.allSettled(holder.starting);
|
|
1200
|
-
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command)))).filter((
|
|
1184
|
+
const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command)))).filter((ended) => !ended).length;
|
|
1201
1185
|
if (stillRunning > 0)
|
|
1202
1186
|
return {
|
|
1203
1187
|
ok: false,
|
|
@@ -1642,7 +1626,8 @@ async function prepareRunner(context, request2) {
|
|
|
1642
1626
|
if (!vcpus.ok) return { kind: "invalid-recipe", path: ["vcpus"], problem: vcpus.problem };
|
|
1643
1627
|
const upload = await checkout.assembleUpload({ repoRoot, base });
|
|
1644
1628
|
if (!upload.ok) return { kind: "checkout-failed", failure: upload.failure };
|
|
1645
|
-
const
|
|
1629
|
+
const reuseBranch = request2.trustBranchSnapshots || !runStepTakesSecret(recipe);
|
|
1630
|
+
const cache = request2.rebuild ? { candidates: [], notes: [] } : await findSnapshotCandidates(context, { repoRoot, recipe, branch: reuseBranch ? head2.value.branch : null });
|
|
1646
1631
|
return {
|
|
1647
1632
|
kind: "ok",
|
|
1648
1633
|
prepared: {
|
|
@@ -1659,20 +1644,118 @@ async function prepareRunner(context, request2) {
|
|
|
1659
1644
|
candidates: cache.candidates,
|
|
1660
1645
|
rebuild: request2.rebuild,
|
|
1661
1646
|
notes: cache.notes,
|
|
1662
|
-
save:
|
|
1647
|
+
save: plannedSave(request2.save, head2.value.branch)
|
|
1663
1648
|
}
|
|
1664
1649
|
};
|
|
1665
1650
|
}
|
|
1651
|
+
function plannedSave(mode, branch) {
|
|
1652
|
+
if (mode === "never") return null;
|
|
1653
|
+
if (branch !== null) return { kind: "branch", branch, always: mode === "always" };
|
|
1654
|
+
return mode === "always" ? { kind: "skipped", reason: "detached-head" } : null;
|
|
1655
|
+
}
|
|
1666
1656
|
|
|
1667
|
-
// src/runner/
|
|
1657
|
+
// src/runner/sandboxed-command.ts
|
|
1668
1658
|
import { posix } from "node:path";
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
return
|
|
1659
|
+
function sandboxedCommand(request2) {
|
|
1660
|
+
const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
|
|
1661
|
+
const cmd = first.includes("/") && !first.startsWith("/") ? posix.join(request2.cwd, first) : first;
|
|
1662
|
+
return { cmd, args: rest };
|
|
1673
1663
|
}
|
|
1674
|
-
function
|
|
1675
|
-
|
|
1664
|
+
function sandboxEnvironment(request2) {
|
|
1665
|
+
const bins = [
|
|
1666
|
+
.../* @__PURE__ */ new Set([posix.join(request2.cwd, "node_modules/.bin"), posix.join(SANDBOX_ROOT, "node_modules/.bin")])
|
|
1667
|
+
];
|
|
1668
|
+
return {
|
|
1669
|
+
PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
|
|
1670
|
+
NO_UPDATE_NOTIFIER: "1",
|
|
1671
|
+
...request2.color ? { FORCE_COLOR: "1" } : { NO_COLOR: "1" },
|
|
1672
|
+
...request2.env,
|
|
1673
|
+
[RUN_PAYLOAD_VARIABLE]: request2.runPayload
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
|
|
1677
|
+
async function runCommandInSandbox(context, request2, control, progress) {
|
|
1678
|
+
const { runner } = request2;
|
|
1679
|
+
const terminal = context.runnerTerminal;
|
|
1680
|
+
const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
|
|
1681
|
+
const env = sandboxEnvironment({
|
|
1682
|
+
cwd: runner.cwd,
|
|
1683
|
+
loginPath: runner.loginPath,
|
|
1684
|
+
color: terminal.color,
|
|
1685
|
+
env: runner.env,
|
|
1686
|
+
runPayload: request2.runPayload
|
|
1687
|
+
});
|
|
1688
|
+
await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
|
|
1689
|
+
const startedAt = context.clock.now().getTime();
|
|
1690
|
+
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
1691
|
+
const write = (stream, text) => {
|
|
1692
|
+
if (text === "") return;
|
|
1693
|
+
const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
|
|
1694
|
+
if (stream === "stdout") terminal.writeStdout(local);
|
|
1695
|
+
else terminal.writeStderr(local);
|
|
1696
|
+
};
|
|
1697
|
+
const following = followTestEvents(context, runner, request2.testEvents, control.kill);
|
|
1698
|
+
const ran = await context.runnerSandboxes.runCommand(
|
|
1699
|
+
runner.sandbox,
|
|
1700
|
+
{ cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
|
|
1701
|
+
({ stream, data }) => write(stream, splitters[stream].push(data)),
|
|
1702
|
+
control.kill
|
|
1703
|
+
);
|
|
1704
|
+
const ms = context.clock.now().getTime() - startedAt;
|
|
1705
|
+
write("stdout", splitters.stdout.flush());
|
|
1706
|
+
write("stderr", splitters.stderr.flush());
|
|
1707
|
+
await following?.end(ran.ok && !control.kill.aborted);
|
|
1708
|
+
if (!ran.ok) {
|
|
1709
|
+
if (ran.failure.kind !== "aborted")
|
|
1710
|
+
return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
|
|
1711
|
+
await progress.emit({ kind: "command-stopped", command: posix.basename(command.cmd) });
|
|
1712
|
+
return { kind: "killed" };
|
|
1713
|
+
}
|
|
1714
|
+
return { kind: "exited", exitCode: ran.value.exitCode, ms };
|
|
1715
|
+
}
|
|
1716
|
+
function followTestEvents(context, runner, testEvents, kill) {
|
|
1717
|
+
if (testEvents === void 0) return void 0;
|
|
1718
|
+
const stop = new AbortController();
|
|
1719
|
+
const splitter = lineSplitter();
|
|
1720
|
+
let handed = 0;
|
|
1721
|
+
const hand = (lines) => {
|
|
1722
|
+
for (const line of lines) {
|
|
1723
|
+
handed += 1;
|
|
1724
|
+
testEvents.onLine(line);
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
const followed = context.runnerSandboxes.followTestEvents(
|
|
1728
|
+
runner.sandbox,
|
|
1729
|
+
{ path: SANDBOX_TEST_EVENTS_PATH },
|
|
1730
|
+
({ data }) => hand(splitLines(splitter.push(data))),
|
|
1731
|
+
stop.signal
|
|
1732
|
+
);
|
|
1733
|
+
return {
|
|
1734
|
+
async end(complete) {
|
|
1735
|
+
stop.abort();
|
|
1736
|
+
await followed;
|
|
1737
|
+
if (!complete) {
|
|
1738
|
+
hand(splitLines(splitter.flush()));
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
const reader = lineSplitter();
|
|
1742
|
+
let read = false;
|
|
1743
|
+
const result = await context.runnerSandboxes.readTestEvents(
|
|
1744
|
+
runner.sandbox,
|
|
1745
|
+
{ path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
|
|
1746
|
+
({ data }) => {
|
|
1747
|
+
if (!read) {
|
|
1748
|
+
splitter.flush();
|
|
1749
|
+
read = true;
|
|
1750
|
+
}
|
|
1751
|
+
hand(splitLines(reader.push(data)));
|
|
1752
|
+
},
|
|
1753
|
+
kill
|
|
1754
|
+
);
|
|
1755
|
+
hand(splitLines(read ? reader.flush() : splitter.flush()));
|
|
1756
|
+
if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1676
1759
|
}
|
|
1677
1760
|
|
|
1678
1761
|
// src/runner/secrets.ts
|
|
@@ -1702,6 +1785,17 @@ function ownValue(map, name) {
|
|
|
1702
1785
|
return Object.hasOwn(map, name) ? map[name] : void 0;
|
|
1703
1786
|
}
|
|
1704
1787
|
|
|
1788
|
+
// src/runner/ready.ts
|
|
1789
|
+
import { posix as posix2 } from "node:path";
|
|
1790
|
+
|
|
1791
|
+
// src/runner/context.ts
|
|
1792
|
+
function runnerPurpose(recipeName) {
|
|
1793
|
+
return `storm-runner-${recipeName}`;
|
|
1794
|
+
}
|
|
1795
|
+
function runnerTags(recipeName, role, user) {
|
|
1796
|
+
return { purpose: runnerPurpose(recipeName), user, role };
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1705
1799
|
// src/runner/snapshot-build.ts
|
|
1706
1800
|
var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
|
|
1707
1801
|
var BASE_INDEX_LABEL = "Committing the base's files";
|
|
@@ -1777,7 +1871,7 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1777
1871
|
await progress.emit({ kind: "snapshot-saving" });
|
|
1778
1872
|
const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
|
|
1779
1873
|
if (!saved.ok) return sandboxStop("save-snapshot", saved.failure);
|
|
1780
|
-
const
|
|
1874
|
+
const savedAt2 = context.clock.now();
|
|
1781
1875
|
const entry = {
|
|
1782
1876
|
teamId: access.teamId,
|
|
1783
1877
|
projectId: access.projectId,
|
|
@@ -1787,8 +1881,8 @@ async function buildSnapshot(context, request2, control, progress) {
|
|
|
1787
1881
|
snapshotKey: prepared.snapshotKey,
|
|
1788
1882
|
base,
|
|
1789
1883
|
snapshotId: saved.value.snapshotId,
|
|
1790
|
-
createdAt:
|
|
1791
|
-
expiresAt: saved.value.expiresAt ?? new Date(
|
|
1884
|
+
createdAt: savedAt2.toISOString(),
|
|
1885
|
+
expiresAt: saved.value.expiresAt ?? new Date(savedAt2.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString()
|
|
1792
1886
|
};
|
|
1793
1887
|
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
1794
1888
|
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
@@ -1925,7 +2019,7 @@ async function readyRunner(context, request2, control, progress) {
|
|
|
1925
2019
|
region: recipe.region,
|
|
1926
2020
|
runtime: recipe.runtime,
|
|
1927
2021
|
repoRoot,
|
|
1928
|
-
cwd:
|
|
2022
|
+
cwd: posix2.join(SANDBOX_ROOT, recipe.cwd),
|
|
1929
2023
|
env: recipe.env,
|
|
1930
2024
|
loginPath: loginPath.value
|
|
1931
2025
|
}
|
|
@@ -1990,136 +2084,32 @@ async function stage(context, request2, signal, progress) {
|
|
|
1990
2084
|
return stop;
|
|
1991
2085
|
}
|
|
1992
2086
|
|
|
1993
|
-
// src/runner/
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
return { cmd, args: rest };
|
|
2087
|
+
// src/runner/scope.ts
|
|
2088
|
+
var CREATE_SETTLE_MS = 2e4;
|
|
2089
|
+
var SNAPSHOT_SETTLE_MS = 2 * 6e4;
|
|
2090
|
+
function unsavedKeepMs(plan) {
|
|
2091
|
+
return plan.kind === "keep" ? plan.ms : plan.otherwiseKeepMs;
|
|
1999
2092
|
}
|
|
2000
|
-
function
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2093
|
+
function runnerSandboxScope(context, progress, keep) {
|
|
2094
|
+
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
2095
|
+
const live = /* @__PURE__ */ new Set();
|
|
2096
|
+
const creating = /* @__PURE__ */ new Set();
|
|
2097
|
+
const saving = /* @__PURE__ */ new Set();
|
|
2098
|
+
const notStopped = [];
|
|
2099
|
+
const notDeleted = [];
|
|
2100
|
+
let kept = null;
|
|
2101
|
+
let notKept = null;
|
|
2102
|
+
let closing;
|
|
2103
|
+
const track = (set, task) => {
|
|
2104
|
+
set.add(task);
|
|
2105
|
+
const forget = () => set.delete(task);
|
|
2106
|
+
void task.then(forget, forget);
|
|
2107
|
+
return task;
|
|
2010
2108
|
};
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
const terminal = context.runnerTerminal;
|
|
2016
|
-
const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
|
|
2017
|
-
const env = sandboxEnvironment({
|
|
2018
|
-
cwd: runner.cwd,
|
|
2019
|
-
loginPath: runner.loginPath,
|
|
2020
|
-
color: terminal.color,
|
|
2021
|
-
env: runner.env,
|
|
2022
|
-
runPayload: request2.runPayload
|
|
2023
|
-
});
|
|
2024
|
-
await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
|
|
2025
|
-
const startedAt = context.clock.now().getTime();
|
|
2026
|
-
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
2027
|
-
const write = (stream, text) => {
|
|
2028
|
-
if (text === "") return;
|
|
2029
|
-
const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
|
|
2030
|
-
if (stream === "stdout") terminal.writeStdout(local);
|
|
2031
|
-
else terminal.writeStderr(local);
|
|
2032
|
-
};
|
|
2033
|
-
const following = followTestEvents(context, runner, request2.testEvents, control.kill);
|
|
2034
|
-
const ran = await context.runnerSandboxes.runCommand(
|
|
2035
|
-
runner.sandbox,
|
|
2036
|
-
{ cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
|
|
2037
|
-
({ stream, data }) => write(stream, splitters[stream].push(data)),
|
|
2038
|
-
control.kill
|
|
2039
|
-
);
|
|
2040
|
-
const ms = context.clock.now().getTime() - startedAt;
|
|
2041
|
-
write("stdout", splitters.stdout.flush());
|
|
2042
|
-
write("stderr", splitters.stderr.flush());
|
|
2043
|
-
await following?.end(ran.ok && !control.kill.aborted);
|
|
2044
|
-
if (!ran.ok) {
|
|
2045
|
-
if (ran.failure.kind !== "aborted")
|
|
2046
|
-
return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
|
|
2047
|
-
await progress.emit({ kind: "command-stopped", command: posix2.basename(command.cmd) });
|
|
2048
|
-
return { kind: "killed" };
|
|
2049
|
-
}
|
|
2050
|
-
return { kind: "exited", exitCode: ran.value.exitCode, ms };
|
|
2051
|
-
}
|
|
2052
|
-
function followTestEvents(context, runner, testEvents, kill) {
|
|
2053
|
-
if (testEvents === void 0) return void 0;
|
|
2054
|
-
const stop = new AbortController();
|
|
2055
|
-
const splitter = lineSplitter();
|
|
2056
|
-
let handed = 0;
|
|
2057
|
-
const hand = (lines) => {
|
|
2058
|
-
for (const line2 of lines) {
|
|
2059
|
-
handed += 1;
|
|
2060
|
-
testEvents.onLine(line2);
|
|
2061
|
-
}
|
|
2062
|
-
};
|
|
2063
|
-
const followed = context.runnerSandboxes.followTestEvents(
|
|
2064
|
-
runner.sandbox,
|
|
2065
|
-
{ path: SANDBOX_TEST_EVENTS_PATH },
|
|
2066
|
-
({ data }) => hand(splitLines(splitter.push(data))),
|
|
2067
|
-
stop.signal
|
|
2068
|
-
);
|
|
2069
|
-
return {
|
|
2070
|
-
async end(complete) {
|
|
2071
|
-
stop.abort();
|
|
2072
|
-
await followed;
|
|
2073
|
-
if (!complete) {
|
|
2074
|
-
hand(splitLines(splitter.flush()));
|
|
2075
|
-
return;
|
|
2076
|
-
}
|
|
2077
|
-
const reader = lineSplitter();
|
|
2078
|
-
let read = false;
|
|
2079
|
-
const result = await context.runnerSandboxes.readTestEvents(
|
|
2080
|
-
runner.sandbox,
|
|
2081
|
-
{ path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
|
|
2082
|
-
({ data }) => {
|
|
2083
|
-
if (!read) {
|
|
2084
|
-
splitter.flush();
|
|
2085
|
-
read = true;
|
|
2086
|
-
}
|
|
2087
|
-
hand(splitLines(reader.push(data)));
|
|
2088
|
-
},
|
|
2089
|
-
kill
|
|
2090
|
-
);
|
|
2091
|
-
hand(splitLines(read ? reader.flush() : splitter.flush()));
|
|
2092
|
-
if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
|
|
2093
|
-
}
|
|
2094
|
-
};
|
|
2095
|
-
}
|
|
2096
|
-
|
|
2097
|
-
// src/runner/scope.ts
|
|
2098
|
-
var CREATE_SETTLE_MS = 2e4;
|
|
2099
|
-
var SNAPSHOT_SETTLE_MS = 2 * 6e4;
|
|
2100
|
-
function keptMs(plan) {
|
|
2101
|
-
return plan.kind === "keep" ? plan.ms : 0;
|
|
2102
|
-
}
|
|
2103
|
-
function runnerSandboxScope(context, progress, keep) {
|
|
2104
|
-
const { runnerSandboxes: sandboxes, timer, clock } = context;
|
|
2105
|
-
const live = /* @__PURE__ */ new Set();
|
|
2106
|
-
const creating2 = /* @__PURE__ */ new Set();
|
|
2107
|
-
const saving = /* @__PURE__ */ new Set();
|
|
2108
|
-
const notStopped = [];
|
|
2109
|
-
const notDeleted = [];
|
|
2110
|
-
let kept = null;
|
|
2111
|
-
let notKept = null;
|
|
2112
|
-
let closing;
|
|
2113
|
-
const track = (set, task) => {
|
|
2114
|
-
set.add(task);
|
|
2115
|
-
const forget = () => set.delete(task);
|
|
2116
|
-
void task.then(forget, forget);
|
|
2117
|
-
return task;
|
|
2118
|
-
};
|
|
2119
|
-
const remove = async (sandbox) => {
|
|
2120
|
-
const deleted = await sandboxes.delete(sandbox);
|
|
2121
|
-
if (!deleted.ok)
|
|
2122
|
-
notDeleted.push({ name: sandbox.name, role: sandbox.role, message: failureMessage(deleted.failure) });
|
|
2109
|
+
const remove = async (sandbox) => {
|
|
2110
|
+
const deleted = await sandboxes.delete(sandbox);
|
|
2111
|
+
if (!deleted.ok)
|
|
2112
|
+
notDeleted.push({ name: sandbox.name, role: sandbox.role, message: failureMessage(deleted.failure) });
|
|
2123
2113
|
};
|
|
2124
2114
|
const stopAndRemove = async (sandbox) => {
|
|
2125
2115
|
const stopped = await sandboxes.stop(sandbox);
|
|
@@ -2135,8 +2125,9 @@ function runnerSandboxScope(context, progress, keep) {
|
|
|
2135
2125
|
await remove(sandbox);
|
|
2136
2126
|
};
|
|
2137
2127
|
const keepOrRemove = async (sandbox) => {
|
|
2138
|
-
|
|
2139
|
-
|
|
2128
|
+
const keepMs = sandbox.role === "runner" ? keep.keepMs() : 0;
|
|
2129
|
+
if (keepMs <= 0) return await stopAndRemove(sandbox);
|
|
2130
|
+
const keeping = await sandboxes.keepRunning(sandbox, { until: new Date(clock.now().getTime() + keepMs) });
|
|
2140
2131
|
if (!keeping.ok) {
|
|
2141
2132
|
notKept = { name: sandbox.name, message: failureMessage(keeping.failure) };
|
|
2142
2133
|
return await stopAndRemove(sandbox);
|
|
@@ -2147,7 +2138,7 @@ function runnerSandboxScope(context, progress, keep) {
|
|
|
2147
2138
|
const owned = (start) => {
|
|
2148
2139
|
if (closing !== void 0) return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
|
|
2149
2140
|
return track(
|
|
2150
|
-
|
|
2141
|
+
creating,
|
|
2151
2142
|
(async () => {
|
|
2152
2143
|
const started = await start();
|
|
2153
2144
|
if (!started.ok) return started;
|
|
@@ -2178,7 +2169,7 @@ function runnerSandboxScope(context, progress, keep) {
|
|
|
2178
2169
|
closing ??= (async () => {
|
|
2179
2170
|
if (saving.size > 0) await progress.emit({ kind: "waiting-for-snapshot", settleMs: SNAPSHOT_SETTLE_MS });
|
|
2180
2171
|
await Promise.all([
|
|
2181
|
-
settleWithin(timer,
|
|
2172
|
+
settleWithin(timer, creating, CREATE_SETTLE_MS),
|
|
2182
2173
|
settleWithin(timer, saving, SNAPSHOT_SETTLE_MS)
|
|
2183
2174
|
]);
|
|
2184
2175
|
const held = [...live];
|
|
@@ -2244,7 +2235,7 @@ async function saveOnce(context, request2, control, progress) {
|
|
|
2244
2235
|
if (!saved.ok)
|
|
2245
2236
|
return saved.failure.kind === "aborted" ? { kind: "stopped" } : { kind: "failed", step: "save-snapshot", message: saved.failure.message };
|
|
2246
2237
|
if (signal.aborted) return { kind: "stopped" };
|
|
2247
|
-
const
|
|
2238
|
+
const savedAt2 = context.clock.now();
|
|
2248
2239
|
const entry = {
|
|
2249
2240
|
teamId: startedFrom.teamId,
|
|
2250
2241
|
projectId: startedFrom.projectId,
|
|
@@ -2257,12 +2248,12 @@ async function saveOnce(context, request2, control, progress) {
|
|
|
2257
2248
|
head: head2,
|
|
2258
2249
|
repoRoot: ready.repoRoot,
|
|
2259
2250
|
snapshotId: saved.value.snapshotId,
|
|
2260
|
-
createdAt:
|
|
2261
|
-
expiresAt: saved.value.expiresAt ?? new Date(
|
|
2251
|
+
createdAt: savedAt2.toISOString(),
|
|
2252
|
+
expiresAt: saved.value.expiresAt ?? new Date(savedAt2.getTime() + SNAPSHOT_EXPIRATION_MS).toISOString()
|
|
2262
2253
|
};
|
|
2263
2254
|
const written = await context.runnerSnapshots.writeEntry(entry);
|
|
2264
2255
|
if (!written.ok) await progress.emit({ kind: "snapshot-entry-not-written", failure: written.failure });
|
|
2265
|
-
const ms =
|
|
2256
|
+
const ms = savedAt2.getTime() - startedAt;
|
|
2266
2257
|
await progress.emit({
|
|
2267
2258
|
kind: "branch-snapshot-saved",
|
|
2268
2259
|
snapshotId: entry.snapshotId,
|
|
@@ -2286,7 +2277,7 @@ async function runSaveScript(context, sandbox, script, signal) {
|
|
|
2286
2277
|
const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
|
|
2287
2278
|
const tail = outputTail(FAILURE_TAIL_LINES);
|
|
2288
2279
|
const keep = (text) => {
|
|
2289
|
-
for (const
|
|
2280
|
+
for (const line of splitLines(text)) tail.add(line);
|
|
2290
2281
|
};
|
|
2291
2282
|
const ran = await context.runnerSandboxes.runScript(
|
|
2292
2283
|
sandbox,
|
|
@@ -2301,8 +2292,98 @@ async function runSaveScript(context, sandbox, script, signal) {
|
|
|
2301
2292
|
const { exitCode } = ran.value;
|
|
2302
2293
|
if (exitCode === 0) return { kind: "ok" };
|
|
2303
2294
|
const lines = tail.lines();
|
|
2304
|
-
const
|
|
2305
|
-
return { kind: "failed", message: lines.length === 0 ?
|
|
2295
|
+
const ended = exitCode === null ? "ended without an exit code" : `exited ${exitCode}`;
|
|
2296
|
+
return { kind: "failed", message: lines.length === 0 ? ended : `${ended}: ${lines.join(" / ")}` };
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
// src/runner/session.ts
|
|
2300
|
+
function savedAt(runner, head2) {
|
|
2301
|
+
const { startedFrom } = runner;
|
|
2302
|
+
return isBranchEntry(startedFrom) && startedFrom.head === head2;
|
|
2303
|
+
}
|
|
2304
|
+
function openRunnerSession(context, request2, control, progress) {
|
|
2305
|
+
const { signal, cleanup } = control;
|
|
2306
|
+
const plan = request2.sandbox;
|
|
2307
|
+
const unsaved = { kind: "keep", ms: unsavedKeepMs(plan) };
|
|
2308
|
+
let saveStarted = false;
|
|
2309
|
+
const keepMs = () => saveStarted ? 0 : unsaved.ms;
|
|
2310
|
+
const scope = runnerSandboxScope(context, progress, { keepMs });
|
|
2311
|
+
const closeScope = async () => ({ ...await scope.close(), target: request2.target });
|
|
2312
|
+
let readying = false;
|
|
2313
|
+
let readied;
|
|
2314
|
+
let commandRunning = false;
|
|
2315
|
+
let ended;
|
|
2316
|
+
const stop = () => {
|
|
2317
|
+
void progress.emit({ kind: "stopping", commandRunning, keepMs: keepMs() }).catch(() => void 0);
|
|
2318
|
+
void scope.close().catch(() => void 0);
|
|
2319
|
+
};
|
|
2320
|
+
if (signal.aborted) stop();
|
|
2321
|
+
else signal.addEventListener("abort", stop, { once: true });
|
|
2322
|
+
return {
|
|
2323
|
+
async ready(access, laneSignal) {
|
|
2324
|
+
if (readying) throw new Error("the runner session readies its runner sandbox once");
|
|
2325
|
+
readying = true;
|
|
2326
|
+
const outcome = await readyRunner(
|
|
2327
|
+
context,
|
|
2328
|
+
{ prepared: request2.prepared, access, user: request2.user, secrets: request2.secrets },
|
|
2329
|
+
{ scope, signal: laneSignal },
|
|
2330
|
+
progress
|
|
2331
|
+
);
|
|
2332
|
+
if (outcome.kind === "ready") readied = outcome.runner;
|
|
2333
|
+
return outcome;
|
|
2334
|
+
},
|
|
2335
|
+
async runCommand(command) {
|
|
2336
|
+
if (readied === void 0) throw new Error("the runner session's runner sandbox isn't ready");
|
|
2337
|
+
commandRunning = true;
|
|
2338
|
+
const ran = await runCommandInSandbox(
|
|
2339
|
+
context,
|
|
2340
|
+
{
|
|
2341
|
+
runner: readied,
|
|
2342
|
+
argv: command.argv,
|
|
2343
|
+
runPayload: command.runPayload,
|
|
2344
|
+
...command.testEvents === void 0 ? {} : { testEvents: command.testEvents }
|
|
2345
|
+
},
|
|
2346
|
+
{ kill: signal },
|
|
2347
|
+
progress
|
|
2348
|
+
);
|
|
2349
|
+
if (ran.kind === "exited") ended = { runner: readied, exitCode: ran.exitCode };
|
|
2350
|
+
return ran;
|
|
2351
|
+
},
|
|
2352
|
+
async finish() {
|
|
2353
|
+
commandRunning = false;
|
|
2354
|
+
const { prepared } = request2;
|
|
2355
|
+
let save = prepared.save?.kind === "skipped" ? prepared.save : null;
|
|
2356
|
+
let action = unsaved;
|
|
2357
|
+
if (plan.kind === "save" && ended !== void 0 && !signal.aborted && (plan.always || ended.exitCode === 0 && !savedAt(ended.runner, prepared.head.commit))) {
|
|
2358
|
+
saveStarted = true;
|
|
2359
|
+
action = plan;
|
|
2360
|
+
const saving = saveBranchSnapshot(
|
|
2361
|
+
context,
|
|
2362
|
+
{ ready: ended.runner, branch: plan.branch, head: prepared.head.commit },
|
|
2363
|
+
{ scope, signal },
|
|
2364
|
+
progress
|
|
2365
|
+
);
|
|
2366
|
+
try {
|
|
2367
|
+
await cleanup.release(plan);
|
|
2368
|
+
} finally {
|
|
2369
|
+
save = await saving;
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
await cleanup.startCleanup(action);
|
|
2373
|
+
const facts = await closeScope();
|
|
2374
|
+
signal.removeEventListener("abort", stop);
|
|
2375
|
+
await cleanup.release(action);
|
|
2376
|
+
return { save, cleanup: facts };
|
|
2377
|
+
},
|
|
2378
|
+
async close() {
|
|
2379
|
+
signal.removeEventListener("abort", stop);
|
|
2380
|
+
try {
|
|
2381
|
+
return await closeScope();
|
|
2382
|
+
} finally {
|
|
2383
|
+
await cleanup.release(unsaved);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
};
|
|
2306
2387
|
}
|
|
2307
2388
|
|
|
2308
2389
|
// src/config/load.ts
|
|
@@ -2391,8 +2472,8 @@ function checkSetting(key, value, settings, problems) {
|
|
|
2391
2472
|
const checked = checkSettingValue(key, value);
|
|
2392
2473
|
if (checked.ok) Object.assign(settings, { [key]: checked.value });
|
|
2393
2474
|
else
|
|
2394
|
-
for (const { path: inside, problem
|
|
2395
|
-
problems.push({ key: [key, ...inside].join("."), location: null, problem
|
|
2475
|
+
for (const { path: inside, problem } of checked.problems)
|
|
2476
|
+
problems.push({ key: [key, ...inside].join("."), location: null, problem });
|
|
2396
2477
|
}
|
|
2397
2478
|
function checkResources(value, definitions, problems) {
|
|
2398
2479
|
if (value === void 0) return {};
|
|
@@ -2457,8 +2538,8 @@ function checkResource(definition, key, value, problems) {
|
|
|
2457
2538
|
if (result.ok) checked[option] = result.value;
|
|
2458
2539
|
else {
|
|
2459
2540
|
valid = false;
|
|
2460
|
-
for (const { path: inside, problem
|
|
2461
|
-
problems.push({ key: [path, ...inside].join("."), location: null, problem
|
|
2541
|
+
for (const { path: inside, problem } of result.problems)
|
|
2542
|
+
problems.push({ key: [path, ...inside].join("."), location: null, problem });
|
|
2462
2543
|
}
|
|
2463
2544
|
}
|
|
2464
2545
|
return valid ? checked : void 0;
|
|
@@ -2466,8 +2547,8 @@ function checkResource(definition, key, value, problems) {
|
|
|
2466
2547
|
function isRecord2(value) {
|
|
2467
2548
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2468
2549
|
}
|
|
2469
|
-
function fileProblem(
|
|
2470
|
-
return { key: null, location: null, problem
|
|
2550
|
+
function fileProblem(problem) {
|
|
2551
|
+
return { key: null, location: null, problem };
|
|
2471
2552
|
}
|
|
2472
2553
|
|
|
2473
2554
|
// src/config/credential-resolver.ts
|
|
@@ -2510,8 +2591,8 @@ function said(text, requestToken) {
|
|
|
2510
2591
|
JWT_PATTERN,
|
|
2511
2592
|
"[redacted]"
|
|
2512
2593
|
);
|
|
2513
|
-
const
|
|
2514
|
-
return
|
|
2594
|
+
const line = redacted.replace(/\s+/g, " ").trim();
|
|
2595
|
+
return line.length <= SAID_LIMIT ? line : `${line.slice(0, SAID_LIMIT - 1)}\u2026`;
|
|
2515
2596
|
}
|
|
2516
2597
|
|
|
2517
2598
|
// src/credential/live/github-actions-token-gateway.ts
|
|
@@ -2619,7 +2700,7 @@ function parseJsonObject(text) {
|
|
|
2619
2700
|
}
|
|
2620
2701
|
}
|
|
2621
2702
|
function lastLine(text) {
|
|
2622
|
-
return text.split("\n").map((
|
|
2703
|
+
return text.split("\n").map((line) => line.trim()).filter((line) => line !== "").at(-1);
|
|
2623
2704
|
}
|
|
2624
2705
|
|
|
2625
2706
|
// src/credential/live/vercel-cli-gateway.ts
|
|
@@ -2674,6 +2755,22 @@ function failedRun(error, stdout, stderr) {
|
|
|
2674
2755
|
|
|
2675
2756
|
// src/credential/source.ts
|
|
2676
2757
|
var REQUESTING_TOKEN_LINE = "Requesting a GitHub Actions OIDC token\u2026";
|
|
2758
|
+
function credentialSourceFor(choice, context, progress) {
|
|
2759
|
+
if (choice.source === "github-actions")
|
|
2760
|
+
return githubActionsSource({
|
|
2761
|
+
gateway: context.githubActionsTokens,
|
|
2762
|
+
clock: context.clock,
|
|
2763
|
+
timer: context.timer,
|
|
2764
|
+
progress
|
|
2765
|
+
});
|
|
2766
|
+
const { target } = choice;
|
|
2767
|
+
return mintSource(target, async () => {
|
|
2768
|
+
await progress.emit({ kind: "minting", target });
|
|
2769
|
+
const minted = await context.credentials.mint(target);
|
|
2770
|
+
await progress.emit({ kind: "minted", target, ok: minted.ok });
|
|
2771
|
+
return minted;
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2677
2774
|
function mintSource(target, mint) {
|
|
2678
2775
|
let outcome;
|
|
2679
2776
|
return {
|
|
@@ -2689,34 +2786,13 @@ function mintSource(target, mint) {
|
|
|
2689
2786
|
}
|
|
2690
2787
|
};
|
|
2691
2788
|
}
|
|
2692
|
-
function obtainedSource(target, credential) {
|
|
2693
|
-
const outcome = Promise.resolve({ ok: true, credential });
|
|
2694
|
-
return {
|
|
2695
|
-
obtain: () => outcome,
|
|
2696
|
-
origin: () => ({ source: "mint", target })
|
|
2697
|
-
};
|
|
2698
|
-
}
|
|
2699
|
-
function credentialSourceFor(choice, context, report) {
|
|
2700
|
-
if (choice.source === "github-actions")
|
|
2701
|
-
return githubActionsSource({
|
|
2702
|
-
gateway: context.githubActionsTokens,
|
|
2703
|
-
clock: context.clock,
|
|
2704
|
-
timer: context.timer,
|
|
2705
|
-
onRequest: report.onRequest
|
|
2706
|
-
});
|
|
2707
|
-
const { target } = choice;
|
|
2708
|
-
return mintSource(target, async () => {
|
|
2709
|
-
await report.onMint(target);
|
|
2710
|
-
return await context.credentials.mint(target);
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
2789
|
var TOKEN_REFRESH_MS = 4 * 6e4;
|
|
2714
2790
|
var RETRY_WAITS_MS = [1e3, 2e3];
|
|
2715
2791
|
function githubActionsSource(context) {
|
|
2716
2792
|
let held;
|
|
2717
2793
|
let inFlight;
|
|
2718
2794
|
const request2 = async () => {
|
|
2719
|
-
await context.
|
|
2795
|
+
await context.progress.emit({ kind: "requesting-token" });
|
|
2720
2796
|
for (let attempt = 1; ; attempt += 1) {
|
|
2721
2797
|
const sentAt = context.clock.now().getTime();
|
|
2722
2798
|
const outcome = await context.gateway.request();
|
|
@@ -2844,11 +2920,9 @@ function credentialResolver(gateways) {
|
|
|
2844
2920
|
if (!chosen.ok) return chosen;
|
|
2845
2921
|
const { progress } = report;
|
|
2846
2922
|
const source = credentialSourceFor(chosen.credential, gateways, {
|
|
2847
|
-
|
|
2848
|
-
await progress?.(`Minting a credential for ${mintTargetText(
|
|
2849
|
-
|
|
2850
|
-
onRequest: async () => {
|
|
2851
|
-
await progress?.(REQUESTING_TOKEN_LINE);
|
|
2923
|
+
emit: async (event) => {
|
|
2924
|
+
if (event.kind === "minting") await progress?.(`Minting a credential for ${mintTargetText(event.target)}\u2026`);
|
|
2925
|
+
else if (event.kind === "requesting-token") await progress?.(REQUESTING_TOKEN_LINE);
|
|
2852
2926
|
}
|
|
2853
2927
|
});
|
|
2854
2928
|
return {
|
|
@@ -2875,12 +2949,12 @@ var problemSchema = z6.object({
|
|
|
2875
2949
|
/** What is wrong, worded to follow the key, or the file name when there is no key. */
|
|
2876
2950
|
problem: z6.string()
|
|
2877
2951
|
});
|
|
2878
|
-
function configProblemLine(file, { key, location, problem
|
|
2879
|
-
const
|
|
2880
|
-
if (key !== null) return `${file}: ${key} ${
|
|
2952
|
+
function configProblemLine(file, { key, location, problem }) {
|
|
2953
|
+
const sentence = `${problem.replace(/\.$/, "")}.`;
|
|
2954
|
+
if (key !== null) return `${file}: ${key} ${sentence}`;
|
|
2881
2955
|
if (location !== null)
|
|
2882
|
-
return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${
|
|
2883
|
-
return `${file}: ${
|
|
2956
|
+
return `${file}:${location.line}${location.column === null ? "" : `:${location.column}`} ${sentence}`;
|
|
2957
|
+
return `${file}: ${sentence}`;
|
|
2884
2958
|
}
|
|
2885
2959
|
var optionValueSchema = z6.object({
|
|
2886
2960
|
/** The option's key path, such as resources.<key>.ttl. */
|
|
@@ -2908,10 +2982,10 @@ function optionValueText({ key, value, source }, configFile) {
|
|
|
2908
2982
|
return `${key} is ${value} by default`;
|
|
2909
2983
|
}
|
|
2910
2984
|
}
|
|
2911
|
-
function optionProblemLine({ key, problem
|
|
2985
|
+
function optionProblemLine({ key, problem, values }, configFile) {
|
|
2912
2986
|
const where2 = values.map((value) => optionValueText(value, configFile));
|
|
2913
2987
|
const sources = where2.length === 0 ? "" : `: ${where2.length === 1 ? where2.join("") : `${where2.slice(0, -1).join(", ")} and ${where2.at(-1) ?? ""}`}`;
|
|
2914
|
-
return `${key} ${
|
|
2988
|
+
return `${key} ${problem.replace(/\.$/, "")}${sources}.`;
|
|
2915
2989
|
}
|
|
2916
2990
|
var configErrors = defineErrors({
|
|
2917
2991
|
invalidConfig: {
|
|
@@ -2926,7 +3000,7 @@ var configErrors = defineErrors({
|
|
|
2926
3000
|
const [first, ...rest] = problems;
|
|
2927
3001
|
return {
|
|
2928
3002
|
message: first === void 0 ? `${file} can't be used.` : configProblemLine(file, first),
|
|
2929
|
-
...rest.length === 0 ? {} : { rows: [["Also", rest.map((
|
|
3003
|
+
...rest.length === 0 ? {} : { rows: [["Also", rest.map((problem) => configProblemLine(file, problem))]] },
|
|
2930
3004
|
next: [{ type: "text", text: `Fix ${file}, then retry.` }]
|
|
2931
3005
|
};
|
|
2932
3006
|
}
|
|
@@ -2943,7 +3017,7 @@ var configErrors = defineErrors({
|
|
|
2943
3017
|
const [first, ...rest] = problems;
|
|
2944
3018
|
return {
|
|
2945
3019
|
message: first === void 0 ? "A resource's options don't fit together." : optionProblemLine(first, configFile),
|
|
2946
|
-
...rest.length === 0 ? {} : { rows: [["Also", rest.map((
|
|
3020
|
+
...rest.length === 0 ? {} : { rows: [["Also", rest.map((problem) => optionProblemLine(problem, configFile))]] },
|
|
2947
3021
|
next: [
|
|
2948
3022
|
{
|
|
2949
3023
|
type: "text",
|
|
@@ -2989,11 +3063,11 @@ function errorLocation(error, name) {
|
|
|
2989
3063
|
const lines = (error.stack ?? "").split("\n");
|
|
2990
3064
|
const escaped = name.replaceAll(".", "\\.");
|
|
2991
3065
|
if (error instanceof SyntaxError) {
|
|
2992
|
-
const
|
|
2993
|
-
if (
|
|
3066
|
+
const line = new RegExp(`${escaped}:(\\d+)$`).exec(lines[0] ?? "")?.[1];
|
|
3067
|
+
if (line === void 0) return void 0;
|
|
2994
3068
|
const frame = lines.slice(1);
|
|
2995
3069
|
const carets = frame.slice(0, frame.indexOf("")).find((text) => /^ *\^+$/.test(text));
|
|
2996
|
-
return carets === void 0 ? { line: Number(
|
|
3070
|
+
return carets === void 0 ? { line: Number(line) } : { line: Number(line), column: carets.indexOf("^") + 1 };
|
|
2997
3071
|
}
|
|
2998
3072
|
for (const text of lines) {
|
|
2999
3073
|
const frame = new RegExp(`${escaped}:(\\d+):(\\d+)\\)?$`).exec(text);
|
|
@@ -3129,10 +3203,10 @@ function planResources(resources, run) {
|
|
|
3129
3203
|
)
|
|
3130
3204
|
};
|
|
3131
3205
|
else
|
|
3132
|
-
for (const { option, problem
|
|
3206
|
+
for (const { option, problem, involves } of refused2)
|
|
3133
3207
|
problems.push({
|
|
3134
3208
|
key: optionKeyPath(key, option),
|
|
3135
|
-
problem
|
|
3209
|
+
problem,
|
|
3136
3210
|
values: involves.flatMap((each) => {
|
|
3137
3211
|
const setting = settings[each];
|
|
3138
3212
|
return setting === void 0 ? [] : [{ key: optionKeyPath(key, each), value: setting.value, source: setting.source }];
|
|
@@ -3202,19 +3276,19 @@ function settleRunResources(file, flags) {
|
|
|
3202
3276
|
function invalidConfig(file, problems) {
|
|
3203
3277
|
return configErrors.invalidConfig({
|
|
3204
3278
|
file,
|
|
3205
|
-
problems: problems.map(({ key, location, problem
|
|
3279
|
+
problems: problems.map(({ key, location, problem }) => ({
|
|
3206
3280
|
key,
|
|
3207
3281
|
location: location === null ? null : { line: location.line, column: location.column ?? null },
|
|
3208
|
-
problem
|
|
3282
|
+
problem
|
|
3209
3283
|
}))
|
|
3210
3284
|
});
|
|
3211
3285
|
}
|
|
3212
3286
|
function invalidResourceOptions(configFile, problems) {
|
|
3213
3287
|
return configErrors.invalidResourceOptions({
|
|
3214
3288
|
configFile,
|
|
3215
|
-
problems: problems.map(({ key, problem
|
|
3289
|
+
problems: problems.map(({ key, problem, values }) => ({
|
|
3216
3290
|
key,
|
|
3217
|
-
problem
|
|
3291
|
+
problem,
|
|
3218
3292
|
values: values.map(({ key: valueKey, value, source }) => ({ key: valueKey, value: valueText(value), source }))
|
|
3219
3293
|
}))
|
|
3220
3294
|
});
|
|
@@ -3243,1428 +3317,9 @@ function configResolver(launcher) {
|
|
|
3243
3317
|
};
|
|
3244
3318
|
}
|
|
3245
3319
|
|
|
3246
|
-
// src/extensions/testserver/credential-facts.ts
|
|
3247
|
-
import { z as z7 } from "zod";
|
|
3248
|
-
var credentialOriginSchema = z7.discriminatedUnion("source", [
|
|
3249
|
-
z7.object({
|
|
3250
|
-
/** The mint. */
|
|
3251
|
-
source: z7.literal("mint"),
|
|
3252
|
-
/** The control plane team the credential was minted for. */
|
|
3253
|
-
team: z7.string(),
|
|
3254
|
-
/** The control plane project the credential was minted for. */
|
|
3255
|
-
project: z7.string()
|
|
3256
|
-
}),
|
|
3257
|
-
z7.object({
|
|
3258
|
-
/** A GitHub Actions OIDC token request. */
|
|
3259
|
-
source: z7.literal("github-actions"),
|
|
3260
|
-
/** The token's aud and repository claims; null when they can't be read. */
|
|
3261
|
-
claims: z7.object({ aud: z7.string(), repository: z7.string() }).nullable()
|
|
3262
|
-
})
|
|
3263
|
-
]);
|
|
3264
|
-
var rejectedCredentialShape = {
|
|
3265
|
-
origin: credentialOriginSchema,
|
|
3266
|
-
/** The one fix: a trusted team and project for the mint, a Trusted Source rule for a GitHub Actions OIDC token. */
|
|
3267
|
-
fix: z7.string()
|
|
3268
|
-
};
|
|
3269
|
-
function rejectedCredentialFacts(origin) {
|
|
3270
|
-
return {
|
|
3271
|
-
origin: origin.source === "mint" ? { source: "mint", ...origin.target } : { source: "github-actions", claims: origin.claims === void 0 ? null : { ...origin.claims } },
|
|
3272
|
-
fix: rejectedCredentialFix(origin)
|
|
3273
|
-
};
|
|
3274
|
-
}
|
|
3275
|
-
function rejectedCredentialFix(origin) {
|
|
3276
|
-
if (origin.source === "mint")
|
|
3277
|
-
return "The Testserver control plane trusts development OIDC tokens only from projects in its Trusted Sources; vercel-internal mints for project vercel on team vercel. Use a trusted team and project, then retry.";
|
|
3278
|
-
const aud = origin.claims?.aud ?? "https://github.com/<owner>";
|
|
3279
|
-
const repository = origin.claims?.repository ?? "<owner>/<repo>";
|
|
3280
|
-
return `The Testserver control plane trusts GitHub Actions OIDC tokens only from repositories in its Trusted Sources. Ask the \`vercel/testserver\` owners for a Trusted Source rule matching \`aud: ${aud}\` and \`repository: ${repository}\`, then rerun the job.`;
|
|
3281
|
-
}
|
|
3282
|
-
function rejectedCredentialText(origin) {
|
|
3283
|
-
return origin.source === "mint" ? `the credential minted for project ${origin.project} on team ${origin.team}` : "the GitHub Actions OIDC token";
|
|
3284
|
-
}
|
|
3285
|
-
function credentialOriginRows(origin) {
|
|
3286
|
-
return origin.source === "mint" ? [["Team", origin.team], ["Project", origin.project]] : [
|
|
3287
|
-
["aud", origin.claims?.aud ?? "unreadable"],
|
|
3288
|
-
["repository", origin.claims?.repository ?? "unreadable"]
|
|
3289
|
-
];
|
|
3290
|
-
}
|
|
3291
|
-
|
|
3292
|
-
// src/extensions/testserver/pr-build-facts.ts
|
|
3293
|
-
import { z as z8 } from "zod";
|
|
3294
|
-
var pullRequestFailureKinds = [
|
|
3295
|
-
"no-token",
|
|
3296
|
-
"not-found",
|
|
3297
|
-
"rejected",
|
|
3298
|
-
"http-error",
|
|
3299
|
-
"connect-failed",
|
|
3300
|
-
"timeout",
|
|
3301
|
-
"malformed"
|
|
3302
|
-
];
|
|
3303
|
-
var prBuildsFailureKinds = ["not-found", "rejected", "http-error", "connect-failed", "timeout", "malformed"];
|
|
3304
|
-
var pullRequestUnreadableSchema = z8.object({
|
|
3305
|
-
/** The pull request number. */
|
|
3306
|
-
pr: z8.number(),
|
|
3307
|
-
/** The repository, vercel/api. */
|
|
3308
|
-
repo: z8.string(),
|
|
3309
|
-
/** Why: no GitHub token on the launch machine, or how reading the pull request from GitHub failed. */
|
|
3310
|
-
kind: z8.enum(pullRequestFailureKinds),
|
|
3311
|
-
/** The HTTP status GitHub answered with; null when it answered none, or with no-token. */
|
|
3312
|
-
status: z8.number().nullable(),
|
|
3313
|
-
/** What GitHub or the connection said, with no token in it; null when nothing. */
|
|
3314
|
-
message: z8.string().nullable(),
|
|
3315
|
-
/** Where the GitHub token came from: GITHUB_TOKEN, GH_TOKEN or gh auth token; null with no-token. */
|
|
3316
|
-
tokenOrigin: z8.enum(["GITHUB_TOKEN", "GH_TOKEN", "gh auth token"]).nullable()
|
|
3317
|
-
});
|
|
3318
|
-
var prBuildsUnlistedSchema = z8.object({
|
|
3319
|
-
pr: z8.number(),
|
|
3320
|
-
/** How reading the runs of vercel/api's Testserver workflow on the pull request, or a run's PR build, from GitHub failed. */
|
|
3321
|
-
failure: z8.object({
|
|
3322
|
-
kind: z8.enum(prBuildsFailureKinds),
|
|
3323
|
-
/** The HTTP status GitHub answered with; null when it answered none. */
|
|
3324
|
-
status: z8.number().nullable(),
|
|
3325
|
-
/** What GitHub or the connection said, with no token in it. */
|
|
3326
|
-
detail: z8.string()
|
|
3327
|
-
})
|
|
3328
|
-
});
|
|
3329
|
-
var prBuildNotReadySchema = z8.object({
|
|
3330
|
-
pr: z8.number(),
|
|
3331
|
-
/** The pull request's head commit, 40 hex characters. */
|
|
3332
|
-
headSha: z8.string(),
|
|
3333
|
-
/** The newest PR build of an older head commit of the pull request; null when it has none. */
|
|
3334
|
-
newest: z8.object({
|
|
3335
|
-
build: z8.string(),
|
|
3336
|
-
/** The head commit the build was made from. */
|
|
3337
|
-
headSha: z8.string(),
|
|
3338
|
-
createdAt: z8.string()
|
|
3339
|
-
}).nullable()
|
|
3340
|
-
});
|
|
3341
|
-
var prBuildExpiredSchema = z8.object({
|
|
3342
|
-
pr: z8.number(),
|
|
3343
|
-
headSha: z8.string(),
|
|
3344
|
-
/** The newest PR build made from the head commit. */
|
|
3345
|
-
build: z8.string(),
|
|
3346
|
-
/** When the Testserver control plane stopped creating Testserver sandboxes from it. */
|
|
3347
|
-
expiresAt: z8.string()
|
|
3348
|
-
});
|
|
3349
|
-
function prBuildRefusalFacts(refusal) {
|
|
3350
|
-
switch (refusal.kind) {
|
|
3351
|
-
case "pull-request-unreadable": {
|
|
3352
|
-
const { failure } = refusal;
|
|
3353
|
-
const said2 = pullRequestSaid(failure);
|
|
3354
|
-
return {
|
|
3355
|
-
key: "pullRequestUnreadable",
|
|
3356
|
-
data: {
|
|
3357
|
-
pr: refusal.pr,
|
|
3358
|
-
repo: TESTSERVER_REPO,
|
|
3359
|
-
kind: failure.kind,
|
|
3360
|
-
status: "status" in failure ? failure.status : null,
|
|
3361
|
-
message: said2,
|
|
3362
|
-
tokenOrigin: refusal.tokenOrigin ?? null
|
|
3363
|
-
}
|
|
3364
|
-
};
|
|
3365
|
-
}
|
|
3366
|
-
case "pr-builds-unlisted": {
|
|
3367
|
-
const { failure } = refusal;
|
|
3368
|
-
return {
|
|
3369
|
-
key: "prBuildsUnlisted",
|
|
3370
|
-
data: {
|
|
3371
|
-
pr: refusal.pr,
|
|
3372
|
-
failure: {
|
|
3373
|
-
kind: failure.kind,
|
|
3374
|
-
status: "status" in failure ? failure.status : null,
|
|
3375
|
-
detail: gitHubSaid(failure)
|
|
3376
|
-
}
|
|
3377
|
-
}
|
|
3378
|
-
};
|
|
3379
|
-
}
|
|
3380
|
-
case "pr-build-not-ready": {
|
|
3381
|
-
const { newest } = refusal;
|
|
3382
|
-
return {
|
|
3383
|
-
key: "prBuildNotReady",
|
|
3384
|
-
data: {
|
|
3385
|
-
pr: refusal.pr,
|
|
3386
|
-
headSha: refusal.headSha,
|
|
3387
|
-
newest: newest === void 0 ? null : { build: newest.build, headSha: newest.headSha, createdAt: newest.createdAt }
|
|
3388
|
-
}
|
|
3389
|
-
};
|
|
3390
|
-
}
|
|
3391
|
-
case "pr-build-expired":
|
|
3392
|
-
return {
|
|
3393
|
-
key: "prBuildExpired",
|
|
3394
|
-
data: { pr: refusal.pr, headSha: refusal.headSha, build: refusal.build, expiresAt: refusal.expiresAt }
|
|
3395
|
-
};
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
function pullRequestSaid(failure) {
|
|
3399
|
-
return failure.kind === "no-token" || failure.kind === "not-found" ? null : gitHubSaid(failure);
|
|
3400
|
-
}
|
|
3401
|
-
function gitHubSaid(failure) {
|
|
3402
|
-
switch (failure.kind) {
|
|
3403
|
-
case "not-found":
|
|
3404
|
-
return "HTTP 404";
|
|
3405
|
-
case "rejected":
|
|
3406
|
-
case "http-error":
|
|
3407
|
-
return failure.message;
|
|
3408
|
-
case "connect-failed":
|
|
3409
|
-
return failure.code;
|
|
3410
|
-
case "timeout":
|
|
3411
|
-
return `no answer within ${failure.seconds}s`;
|
|
3412
|
-
case "malformed":
|
|
3413
|
-
return failure.detail;
|
|
3414
|
-
}
|
|
3415
|
-
}
|
|
3416
|
-
function sentence(text) {
|
|
3417
|
-
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
3418
|
-
}
|
|
3419
|
-
function pullRequestName(pr) {
|
|
3420
|
-
return `${TESTSERVER_REPO}#${pr}`;
|
|
3421
|
-
}
|
|
3422
|
-
function pullRequestUrl(pr) {
|
|
3423
|
-
return `https://github.com/${TESTSERVER_REPO}/pull/${pr}`;
|
|
3424
|
-
}
|
|
3425
|
-
function checksStep(pr) {
|
|
3426
|
-
return {
|
|
3427
|
-
type: "external",
|
|
3428
|
-
argv: ["gh", "pr", "checks", String(pr), "--repo", TESTSERVER_REPO],
|
|
3429
|
-
label: "Show the pull request's checks"
|
|
3430
|
-
};
|
|
3431
|
-
}
|
|
3432
|
-
function pullRequestUnreadableContent({ pr, kind: kind2, status, message, tokenOrigin }, outcome) {
|
|
3433
|
-
const name = pullRequestName(pr);
|
|
3434
|
-
const origin = tokenOrigin ?? "the launch machine";
|
|
3435
|
-
const text = (() => {
|
|
3436
|
-
switch (kind2) {
|
|
3437
|
-
case "no-token":
|
|
3438
|
-
return `storm needs a GitHub token to read ${name}. Set GITHUB_TOKEN or GH_TOKEN, or run gh auth login.`;
|
|
3439
|
-
case "not-found":
|
|
3440
|
-
return `${name} doesn't exist, or the token from ${origin} can't read ${TESTSERVER_REPO}.`;
|
|
3441
|
-
case "rejected":
|
|
3442
|
-
return `GitHub refused the token from ${origin} (HTTP ${status ?? "error"}): ${message ?? ""}`;
|
|
3443
|
-
case "http-error":
|
|
3444
|
-
return `GitHub couldn't read ${name} (HTTP ${status ?? "error"}): ${message ?? ""}`;
|
|
3445
|
-
case "connect-failed":
|
|
3446
|
-
return `Couldn't reach GitHub to read ${name} (${message ?? "no connection"}).`;
|
|
3447
|
-
case "timeout":
|
|
3448
|
-
return `GitHub didn't answer the request for ${name}: ${message ?? "timeout"}.`;
|
|
3449
|
-
case "malformed":
|
|
3450
|
-
return `GitHub's answer for ${name} isn't a pull request: ${message ?? ""}`;
|
|
3451
|
-
}
|
|
3452
|
-
})();
|
|
3453
|
-
return {
|
|
3454
|
-
message: `${sentence(text)} ${outcome}`,
|
|
3455
|
-
rows: [
|
|
3456
|
-
["Pull request", pullRequestUrl(pr)],
|
|
3457
|
-
...tokenOrigin === null ? [] : [["GitHub token from", tokenOrigin]]
|
|
3458
|
-
],
|
|
3459
|
-
next: [
|
|
3460
|
-
{ type: "external", argv: ["gh", "auth", "status"], label: "Check the GitHub login" },
|
|
3461
|
-
{
|
|
3462
|
-
type: "text",
|
|
3463
|
-
text: `Run gh auth login, or set GITHUB_TOKEN to a token that can read ${TESTSERVER_REPO}. Then retry.`
|
|
3464
|
-
}
|
|
3465
|
-
]
|
|
3466
|
-
};
|
|
3467
|
-
}
|
|
3468
|
-
function prBuildsUnlistedContent({ pr, failure }, outcome) {
|
|
3469
|
-
return {
|
|
3470
|
-
message: `${sentence(`Couldn't read ${pullRequestName(pr)}'s Testserver builds from GitHub Actions: ${failure.kind}${failure.status === null ? "" : ` (HTTP ${failure.status})`}: ${failure.detail}`)} ${outcome}`,
|
|
3471
|
-
next: [
|
|
3472
|
-
{ type: "external", argv: ["gh", "auth", "status"], label: "Check the GitHub login" },
|
|
3473
|
-
{ type: "text", text: `Make sure that the token can read ${TESTSERVER_REPO}'s Actions, then retry.` }
|
|
3474
|
-
]
|
|
3475
|
-
};
|
|
3476
|
-
}
|
|
3477
|
-
function prBuildNotReadyContent({ pr, headSha, newest }, outcome) {
|
|
3478
|
-
const name = pullRequestName(pr);
|
|
3479
|
-
const text = newest === null ? `${name} has no Testserver build from its head, ${shortSha(headSha)}, yet.` : `${name}'s newest Testserver build, ${newest.build}, is from ${shortSha(newest.headSha)}; the PR's head is ${shortSha(headSha)}.`;
|
|
3480
|
-
return {
|
|
3481
|
-
message: `${text} ${outcome}`,
|
|
3482
|
-
rows: [
|
|
3483
|
-
["Pull request", pullRequestUrl(pr)],
|
|
3484
|
-
["Head commit", headSha],
|
|
3485
|
-
["Newest build", newest === null ? "none" : `${newest.build} (${newest.createdAt})`]
|
|
3486
|
-
],
|
|
3487
|
-
next: [
|
|
3488
|
-
{
|
|
3489
|
-
type: "text",
|
|
3490
|
-
text: "Wait for the Bundle & Publish check on the PR's head to pass, then retry. If the check failed, push a fix to the PR."
|
|
3491
|
-
},
|
|
3492
|
-
checksStep(pr)
|
|
3493
|
-
]
|
|
3494
|
-
};
|
|
3495
|
-
}
|
|
3496
|
-
function prBuildExpiredContent({ pr, headSha, build, expiresAt }, outcome) {
|
|
3497
|
-
return {
|
|
3498
|
-
message: `${pullRequestName(pr)}'s build for its head, ${build}, expired at ${expiresAt}. ${outcome}`,
|
|
3499
|
-
rows: [
|
|
3500
|
-
["Pull request", pullRequestUrl(pr)],
|
|
3501
|
-
["Head commit", headSha]
|
|
3502
|
-
],
|
|
3503
|
-
next: [
|
|
3504
|
-
{
|
|
3505
|
-
type: "text",
|
|
3506
|
-
text: `Push to the PR, or rerun its Testserver workflow (gh run rerun <run-id> --repo ${TESTSERVER_REPO}, or the PR's Checks page). Then retry.`
|
|
3507
|
-
},
|
|
3508
|
-
checksStep(pr)
|
|
3509
|
-
]
|
|
3510
|
-
};
|
|
3511
|
-
}
|
|
3512
|
-
var PR_BUILD_REFUSAL_DESCRIPTIONS = {
|
|
3513
|
-
pullRequestUnreadable: "storm couldn't read the vercel/api pull request that the PR build reference names from GitHub. It has no GitHub token, or GitHub refused the request. storm reads the token from GITHUB_TOKEN, then GH_TOKEN, then gh auth token.",
|
|
3514
|
-
prBuildsUnlisted: "storm couldn't read from GitHub the runs of vercel/api's Testserver workflow on the pull request that the PR build reference names, or the PR build a run published.",
|
|
3515
|
-
prBuildNotReady: "No run of vercel/api's Testserver workflow for the pull request's head commit has published a Testserver build: the Bundle & Publish check of the newest push has not finished, or it failed. storm never runs on a build from an older commit.",
|
|
3516
|
-
prBuildExpired: "The newest Testserver build from the vercel/api pull request's head commit was published 7 days ago or more, so the Testserver control plane creates no Testserver sandbox from it."
|
|
3517
|
-
};
|
|
3518
|
-
function prBuildRefusalErrors(outcome) {
|
|
3519
|
-
return {
|
|
3520
|
-
pullRequestUnreadable: {
|
|
3521
|
-
exitCode: 1,
|
|
3522
|
-
description: PR_BUILD_REFUSAL_DESCRIPTIONS.pullRequestUnreadable,
|
|
3523
|
-
schema: pullRequestUnreadableSchema,
|
|
3524
|
-
render: (data) => pullRequestUnreadableContent(data, outcome)
|
|
3525
|
-
},
|
|
3526
|
-
prBuildsUnlisted: {
|
|
3527
|
-
exitCode: 1,
|
|
3528
|
-
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildsUnlisted,
|
|
3529
|
-
schema: prBuildsUnlistedSchema,
|
|
3530
|
-
render: (data) => prBuildsUnlistedContent(data, outcome)
|
|
3531
|
-
},
|
|
3532
|
-
prBuildNotReady: {
|
|
3533
|
-
exitCode: 1,
|
|
3534
|
-
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildNotReady,
|
|
3535
|
-
schema: prBuildNotReadySchema,
|
|
3536
|
-
render: (data) => prBuildNotReadyContent(data, outcome)
|
|
3537
|
-
},
|
|
3538
|
-
prBuildExpired: {
|
|
3539
|
-
exitCode: 1,
|
|
3540
|
-
description: PR_BUILD_REFUSAL_DESCRIPTIONS.prBuildExpired,
|
|
3541
|
-
schema: prBuildExpiredSchema,
|
|
3542
|
-
render: (data) => prBuildExpiredContent(data, outcome)
|
|
3543
|
-
}
|
|
3544
|
-
};
|
|
3545
|
-
}
|
|
3546
|
-
function prBuildRefusal(refusal, outcome) {
|
|
3547
|
-
const facts = prBuildRefusalFacts(refusal);
|
|
3548
|
-
const content = (() => {
|
|
3549
|
-
switch (facts.key) {
|
|
3550
|
-
case "pullRequestUnreadable":
|
|
3551
|
-
return pullRequestUnreadableContent(facts.data, outcome);
|
|
3552
|
-
case "prBuildsUnlisted":
|
|
3553
|
-
return prBuildsUnlistedContent(facts.data, outcome);
|
|
3554
|
-
case "prBuildNotReady":
|
|
3555
|
-
return prBuildNotReadyContent(facts.data, outcome);
|
|
3556
|
-
case "prBuildExpired":
|
|
3557
|
-
return prBuildExpiredContent(facts.data, outcome);
|
|
3558
|
-
}
|
|
3559
|
-
})();
|
|
3560
|
-
return { refused: PR_BUILD_REASONS[facts.key], data: { ...facts.data }, ...content };
|
|
3561
|
-
}
|
|
3562
|
-
var PR_BUILD_REASONS = {
|
|
3563
|
-
pullRequestUnreadable: "pull_request_unreadable",
|
|
3564
|
-
prBuildsUnlisted: "pr_builds_unlisted",
|
|
3565
|
-
prBuildNotReady: "pr_build_not_ready",
|
|
3566
|
-
prBuildExpired: "pr_build_expired"
|
|
3567
|
-
};
|
|
3568
|
-
|
|
3569
|
-
// src/extensions/testserver/run/connection.ts
|
|
3570
|
-
var TESTSERVER_POOL_NAME = "testserverPool";
|
|
3571
|
-
function checkTestserverConnection(section) {
|
|
3572
|
-
if (!isObject(section)) return problem([], "must be an object");
|
|
3573
|
-
const { sandboxes } = section;
|
|
3574
|
-
if (!Array.isArray(sandboxes)) return problem(["sandboxes"], "must be an array");
|
|
3575
|
-
const checked = [];
|
|
3576
|
-
for (const [index, sandbox] of sandboxes.entries()) {
|
|
3577
|
-
if (!isObject(sandbox)) return problem(["sandboxes", index], "must be an object");
|
|
3578
|
-
const { url } = sandbox;
|
|
3579
|
-
if (typeof url !== "string" || url === "") {
|
|
3580
|
-
return problem(["sandboxes", index, "url"], "must be a non-empty string");
|
|
3581
|
-
}
|
|
3582
|
-
checked.push({ url });
|
|
3583
|
-
}
|
|
3584
|
-
return { ok: true, value: { sandboxes: checked } };
|
|
3585
|
-
}
|
|
3586
|
-
function isObject(value) {
|
|
3587
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3588
|
-
}
|
|
3589
|
-
function problem(at, text) {
|
|
3590
|
-
return { ok: false, at, problem: text };
|
|
3591
|
-
}
|
|
3592
|
-
var testserverConnection = Object.freeze({ name: TESTSERVER_POOL_NAME, payload: checkTestserverConnection });
|
|
3593
|
-
|
|
3594
|
-
// src/extensions/testserver/canceled.ts
|
|
3595
|
-
function testserverCanceledLines(facts) {
|
|
3596
|
-
const { pooled, unpooled, failedCreates, ttlMinutes: ttlMinutes2 } = facts;
|
|
3597
|
-
const ttl = ttlMinutes2 === void 0 ? "its TTL" : describeTtl(ttlMinutes2);
|
|
3598
|
-
const lines = [];
|
|
3599
|
-
if (pooled > 0) {
|
|
3600
|
-
const sandboxes = pooled === 1 ? "Testserver sandbox" : `${pooled} Testserver sandboxes`;
|
|
3601
|
-
lines.push(`It added the ${sandboxes} it created to the pool.`);
|
|
3602
|
-
}
|
|
3603
|
-
if (unpooled.length > 0) {
|
|
3604
|
-
const one = unpooled.length === 1;
|
|
3605
|
-
lines.push(
|
|
3606
|
-
`It couldn't add ${one ? "a" : unpooled.length} Testserver ${one ? "sandbox" : "sandboxes"} it created to the pool; ${one ? "it expires" : "they expire"} within ${ttl}:`,
|
|
3607
|
-
...unpooled.map(({ testserverUrl, failure }) => ` ${testserverUrl}: ${failure.message}`)
|
|
3608
|
-
);
|
|
3609
|
-
}
|
|
3610
|
-
if (failedCreates.some(mayLeaveSandbox))
|
|
3611
|
-
lines.push(
|
|
3612
|
-
`A create that reached the Testserver control plane may have left a Testserver sandbox; nothing can delete it, and it expires within ${ttl}.`
|
|
3613
|
-
);
|
|
3614
|
-
return lines;
|
|
3615
|
-
}
|
|
3616
|
-
|
|
3617
|
-
// src/extensions/testserver/limit.ts
|
|
3618
|
-
async function runLimited(count2, limit, proceed, task) {
|
|
3619
|
-
const results = Array.from({ length: count2 }, () => void 0);
|
|
3620
|
-
let failure;
|
|
3621
|
-
let next = 0;
|
|
3622
|
-
const worker = async () => {
|
|
3623
|
-
while (failure === void 0 && next < count2 && proceed()) {
|
|
3624
|
-
const index = next;
|
|
3625
|
-
next += 1;
|
|
3626
|
-
try {
|
|
3627
|
-
results[index] = await task(index);
|
|
3628
|
-
} catch (error) {
|
|
3629
|
-
failure ??= { error };
|
|
3630
|
-
}
|
|
3631
|
-
}
|
|
3632
|
-
};
|
|
3633
|
-
await Promise.all(Array.from({ length: Math.min(limit, count2) }, worker));
|
|
3634
|
-
if (failure !== void 0) throw failure.error;
|
|
3635
|
-
return results;
|
|
3636
|
-
}
|
|
3637
|
-
|
|
3638
|
-
// src/extensions/testserver/provision.ts
|
|
3639
|
-
function unpooledFacts(unpooled) {
|
|
3640
|
-
return unpooled.map(({ testserverUrl, failure }) => ({
|
|
3641
|
-
testserverUrl,
|
|
3642
|
-
path: failure.path,
|
|
3643
|
-
message: failure.message
|
|
3644
|
-
}));
|
|
3645
|
-
}
|
|
3646
|
-
function failedCreateFacts(failures) {
|
|
3647
|
-
return failures.map((failure) => {
|
|
3648
|
-
const { kind: kind2, detail } = describeCreateFailure(failure);
|
|
3649
|
-
return { kind: kind2, detail };
|
|
3650
|
-
});
|
|
3651
|
-
}
|
|
3652
|
-
function createWith(options, credential) {
|
|
3653
|
-
if (!options.create) return void 0;
|
|
3654
|
-
if (credential === void 0)
|
|
3655
|
-
throw new Error("A Testserver pool that creates needs the Vercel credential, so its run chooses a source.");
|
|
3656
|
-
return { source: credential, ttlMinutes: ttlMinutes(options) };
|
|
3657
|
-
}
|
|
3658
|
-
function credentialFailed(failure, ttlMinutes2, failedCreates) {
|
|
3659
|
-
return failure.source === "mint" ? { kind: "mint-failed", failed: failure } : { kind: "token-request-failed", failure: failure.failure, ttlMinutes: ttlMinutes2, failedCreates };
|
|
3660
|
-
}
|
|
3661
|
-
function testserverCanceledFacts(options, facts) {
|
|
3662
|
-
return canceledAfter(facts, options.create ? ttlMinutes(options) : void 0);
|
|
3663
|
-
}
|
|
3664
|
-
function canceledAfter(facts, ttlMinutes2) {
|
|
3665
|
-
const created = facts.sandboxes.filter((sandbox) => sandbox.origin === "created").length;
|
|
3666
|
-
return {
|
|
3667
|
-
pooled: created - facts.unpooled.length,
|
|
3668
|
-
unpooled: facts.unpooled,
|
|
3669
|
-
failedCreates: facts.failedCreates,
|
|
3670
|
-
ttlMinutes: ttlMinutes2
|
|
3671
|
-
};
|
|
3672
|
-
}
|
|
3673
|
-
async function provision(world, options, create, signal, report, take) {
|
|
3674
|
-
let tally = { created: [], failedCreates: [], unpooled: [] };
|
|
3675
|
-
const canceled = () => ({
|
|
3676
|
-
kind: "canceled",
|
|
3677
|
-
pooled: tally.created.length - tally.unpooled.length,
|
|
3678
|
-
unpooled: tally.unpooled,
|
|
3679
|
-
failedCreates: tally.failedCreates,
|
|
3680
|
-
ttlMinutes: create?.ttlMinutes
|
|
3681
|
-
});
|
|
3682
|
-
if (signal.aborted) return canceled();
|
|
3683
|
-
const reference = parseBuildReference(options.build);
|
|
3684
|
-
let resolution;
|
|
3685
|
-
if (reference.ok && reference.reference.kind === "pull-request") {
|
|
3686
|
-
const resolved = await resolvePullRequestBuild(world, reference.reference.number, report);
|
|
3687
|
-
if (resolved.kind !== "resolved") return resolved;
|
|
3688
|
-
resolution = resolved.resolution;
|
|
3689
|
-
} else {
|
|
3690
|
-
resolution = await resolveBuild(world, { build: options.build, credential: create?.source });
|
|
3691
|
-
if (resolution.kind === "as-written")
|
|
3692
|
-
await report.progress({ kind: "build-unresolved", channel: resolution.channel, reason: resolution.reason });
|
|
3693
|
-
if (resolution.kind === "old-channel-resolution")
|
|
3694
|
-
await report.progress({
|
|
3695
|
-
kind: "old-channel-resolution",
|
|
3696
|
-
channel: resolution.channel,
|
|
3697
|
-
build: resolution.build,
|
|
3698
|
-
ageMinutes: minutesSince(resolution.learnedAt, world.clock.now())
|
|
3699
|
-
});
|
|
3700
|
-
}
|
|
3701
|
-
if (signal.aborted) return canceled();
|
|
3702
|
-
const match = buildMatch(resolution);
|
|
3703
|
-
await report.progress({ kind: "leasing", match, requested: options.sandboxes });
|
|
3704
|
-
const leasedOutcome = await leaseUsable(world, {
|
|
3705
|
-
match,
|
|
3706
|
-
count: options.sandboxes,
|
|
3707
|
-
minTimeLeftMinutes: minTimeLeftMinutes(options)
|
|
3708
|
-
});
|
|
3709
|
-
if (!leasedOutcome.ok) return { kind: "pool-unreadable", failure: leasedOutcome.failure };
|
|
3710
|
-
const upkeep = leasedOutcome.report;
|
|
3711
|
-
for (const { host } of upkeep.leased) take(host);
|
|
3712
|
-
await report.progress({ kind: "leased", match, requested: options.sandboxes, report: upkeep });
|
|
3713
|
-
const reused = upkeep.leased.map(({ entry }) => ({
|
|
3714
|
-
testserverUrl: entry.testserverUrl,
|
|
3715
|
-
logViewerUrl: entry.logViewerUrl,
|
|
3716
|
-
origin: "reused"
|
|
3717
|
-
}));
|
|
3718
|
-
let uncreated;
|
|
3719
|
-
let notCreated = 0;
|
|
3720
|
-
const missing = options.sandboxes - reused.length;
|
|
3721
|
-
if (missing > 0 && create === void 0) {
|
|
3722
|
-
if (reused.length === 0) return { kind: "no-usable-sandboxes", requested: options.sandboxes, match };
|
|
3723
|
-
notCreated = missing;
|
|
3724
|
-
} else if (missing > 0 && create !== void 0) {
|
|
3725
|
-
if (signal.aborted) return canceled();
|
|
3726
|
-
const { rejected, credentialFailure, uncreatedCount, ...made } = await createMissing(
|
|
3727
|
-
world,
|
|
3728
|
-
{
|
|
3729
|
-
source: create.source,
|
|
3730
|
-
target: createTarget(options.build, resolution),
|
|
3731
|
-
ttlMinutes: create.ttlMinutes,
|
|
3732
|
-
count: missing
|
|
3733
|
-
},
|
|
3734
|
-
signal,
|
|
3735
|
-
report,
|
|
3736
|
-
take
|
|
3737
|
-
);
|
|
3738
|
-
tally = made;
|
|
3739
|
-
if (rejected !== void 0)
|
|
3740
|
-
return {
|
|
3741
|
-
kind: "credential-rejected",
|
|
3742
|
-
failure: rejected.failure,
|
|
3743
|
-
origin: create.source.origin(rejected.credential),
|
|
3744
|
-
ttlMinutes: create.ttlMinutes,
|
|
3745
|
-
failedCreates: tally.failedCreates,
|
|
3746
|
-
unpooled: tally.unpooled
|
|
3747
|
-
};
|
|
3748
|
-
if (signal.aborted) return canceled();
|
|
3749
|
-
if (credentialFailure !== void 0) {
|
|
3750
|
-
if (reused.length === 0 && tally.created.length === 0)
|
|
3751
|
-
return credentialFailed(credentialFailure, create.ttlMinutes, tally.failedCreates);
|
|
3752
|
-
uncreated = { count: uncreatedCount, failure: credentialFailure };
|
|
3753
|
-
}
|
|
3754
|
-
if (reused.length === 0 && tally.created.length === 0)
|
|
3755
|
-
return {
|
|
3756
|
-
kind: "no-sandboxes",
|
|
3757
|
-
requested: options.sandboxes,
|
|
3758
|
-
ttlMinutes: create.ttlMinutes,
|
|
3759
|
-
failedCreates: tally.failedCreates
|
|
3760
|
-
};
|
|
3761
|
-
}
|
|
3762
|
-
const sandboxes = [...reused, ...tally.created];
|
|
3763
|
-
if (signal.aborted) return canceled();
|
|
3764
|
-
return {
|
|
3765
|
-
kind: "provisioned",
|
|
3766
|
-
resolution,
|
|
3767
|
-
sandboxes,
|
|
3768
|
-
failedCreates: tally.failedCreates,
|
|
3769
|
-
unpooled: tally.unpooled,
|
|
3770
|
-
uncreated,
|
|
3771
|
-
notCreated
|
|
3772
|
-
};
|
|
3773
|
-
}
|
|
3774
|
-
async function resolvePullRequestBuild(world, pr, report) {
|
|
3775
|
-
const outcome = await resolvePrBuild(world, { pr });
|
|
3776
|
-
if (!outcome.ok) return outcome.refusal;
|
|
3777
|
-
const { resolution } = outcome;
|
|
3778
|
-
const { headSha, build, merged, from } = resolution;
|
|
3779
|
-
await report.progress({ kind: "pr-build-resolved", pr, headSha, build, merged, from });
|
|
3780
|
-
return { kind: "resolved", resolution };
|
|
3781
|
-
}
|
|
3782
|
-
function createTarget(requestedBuild, resolution) {
|
|
3783
|
-
return resolution.kind === "pull-request" ? { build: resolution.build, requestedBuild, headSha: resolution.headSha } : { build: requestedBuild, requestedBuild };
|
|
3784
|
-
}
|
|
3785
|
-
async function createMissing(world, request2, signal, report, take) {
|
|
3786
|
-
const { source, target, ttlMinutes: ttlMinutes2, count: count2 } = request2;
|
|
3787
|
-
const first = await source.obtain();
|
|
3788
|
-
if (!first.ok)
|
|
3789
|
-
return {
|
|
3790
|
-
created: [],
|
|
3791
|
-
failedCreates: [],
|
|
3792
|
-
unpooled: [],
|
|
3793
|
-
rejected: void 0,
|
|
3794
|
-
credentialFailure: first.failure,
|
|
3795
|
-
uncreatedCount: count2
|
|
3796
|
-
};
|
|
3797
|
-
await report.progress({ kind: "creating", count: count2, build: target.build });
|
|
3798
|
-
let rejected;
|
|
3799
|
-
let credentialFailure;
|
|
3800
|
-
const mayCreate = () => rejected === void 0 && credentialFailure === void 0 && !signal.aborted;
|
|
3801
|
-
const outcomes = await runLimited(
|
|
3802
|
-
count2,
|
|
3803
|
-
CREATE_CONCURRENCY,
|
|
3804
|
-
mayCreate,
|
|
3805
|
-
async (index) => {
|
|
3806
|
-
const got = await source.obtain();
|
|
3807
|
-
if (!got.ok) {
|
|
3808
|
-
credentialFailure ??= got.failure;
|
|
3809
|
-
return void 0;
|
|
3810
|
-
}
|
|
3811
|
-
if (!mayCreate()) return void 0;
|
|
3812
|
-
const { credential } = got;
|
|
3813
|
-
await report.progress({ kind: "create-started", index, count: count2 });
|
|
3814
|
-
const outcome = await createPooledSandbox(
|
|
3815
|
-
world,
|
|
3816
|
-
{ credential, ...target, ttlMinutes: ttlMinutes2, lease: true },
|
|
3817
|
-
{ onProgress: (message) => report.progress({ kind: "create-progress", index, count: count2, message }) }
|
|
3818
|
-
);
|
|
3819
|
-
if (outcome.kind === "pooled") take(outcome.host);
|
|
3820
|
-
if (outcome.kind === "create-failed" && outcome.failure.kind === "rejected")
|
|
3821
|
-
rejected ??= { failure: outcome.failure, credential };
|
|
3822
|
-
await report.progress({ kind: "create-finished", index, count: count2, outcome });
|
|
3823
|
-
return outcome;
|
|
3824
|
-
}
|
|
3825
|
-
);
|
|
3826
|
-
const created = [];
|
|
3827
|
-
const failedCreates = [];
|
|
3828
|
-
const unpooled = [];
|
|
3829
|
-
let uncreatedCount = 0;
|
|
3830
|
-
for (const outcome of outcomes) {
|
|
3831
|
-
if (outcome === void 0) {
|
|
3832
|
-
uncreatedCount += 1;
|
|
3833
|
-
continue;
|
|
3834
|
-
}
|
|
3835
|
-
if (outcome.kind === "create-failed") {
|
|
3836
|
-
const { failure } = outcome;
|
|
3837
|
-
if (failure.kind !== "rejected") failedCreates.push(failure);
|
|
3838
|
-
continue;
|
|
3839
|
-
}
|
|
3840
|
-
const { testserverUrl, logViewerUrl } = outcome.entry;
|
|
3841
|
-
created.push({ testserverUrl, logViewerUrl, origin: "created" });
|
|
3842
|
-
if (outcome.kind === "pool-write-failed") unpooled.push({ testserverUrl, failure: outcome.failure });
|
|
3843
|
-
}
|
|
3844
|
-
return { created, failedCreates, unpooled, rejected, credentialFailure, uncreatedCount };
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
// src/extensions/testserver/refusals.ts
|
|
3848
|
-
var NOT_RUN = "The command didn't run.";
|
|
3849
|
-
function unpooledRows(unpooled) {
|
|
3850
|
-
return unpooled.length === 0 ? [] : [["Unpooled Testserver sandboxes", unpooled.map(({ testserverUrl, message }) => `${testserverUrl}: ${message}`)]];
|
|
3851
|
-
}
|
|
3852
|
-
function failedCreateRows(failedCreates) {
|
|
3853
|
-
return failedCreates.length === 0 ? [] : [["Failed creates", failedCreates.map(createFailureText)]];
|
|
3854
|
-
}
|
|
3855
|
-
function sandboxMayExist(ttlMinutes2) {
|
|
3856
|
-
return `A create that reached the Testserver control plane may have left a Testserver sandbox anyway; nothing can delete it, and it expires within ${describeTtl(ttlMinutes2)}.`;
|
|
3857
|
-
}
|
|
3858
|
-
function mayExistSteps(mayExist, ttlMinutes2) {
|
|
3859
|
-
return mayExist ? [{ type: "text", text: sandboxMayExist(ttlMinutes2) }] : [];
|
|
3860
|
-
}
|
|
3861
|
-
var CREATE_KEY_PATH = optionKeyPath("testserverPool", "create");
|
|
3862
|
-
function poolUnavailable(data) {
|
|
3863
|
-
return {
|
|
3864
|
-
refused: "pool_unavailable",
|
|
3865
|
-
data: { path: data.path, message: data.message },
|
|
3866
|
-
message: `Couldn't prepare the pool: ${data.message}`,
|
|
3867
|
-
rows: [["Pool path", data.path]],
|
|
3868
|
-
next: [{ type: "text", text: `Fix the pool path, then retry. ${NOT_RUN}` }]
|
|
3869
|
-
};
|
|
3870
|
-
}
|
|
3871
|
-
function poolUnreadable(data) {
|
|
3872
|
-
return {
|
|
3873
|
-
refused: "pool_unreadable",
|
|
3874
|
-
data: { path: data.path, message: data.message },
|
|
3875
|
-
message: `Couldn't read the pool: ${data.message}`,
|
|
3876
|
-
rows: [["Pool path", data.path]],
|
|
3877
|
-
next: [{ type: "text", text: `Fix the pool path, then retry. ${NOT_RUN}` }]
|
|
3878
|
-
};
|
|
3879
|
-
}
|
|
3880
|
-
function tokenRequestFailed(failure, data) {
|
|
3881
|
-
const facts = tokenRequestFailureFacts(failure);
|
|
3882
|
-
const { ttlMinutes: ttlMinutes2, failedCreates, sandboxMayExist: mayExist } = data;
|
|
3883
|
-
return {
|
|
3884
|
-
refused: "token_request_failed",
|
|
3885
|
-
data: { ...facts, ...data },
|
|
3886
|
-
message: `Couldn't request a GitHub Actions OIDC token: ${facts.detail}. The pool had no usable Testserver sandbox, so the command didn't run.`,
|
|
3887
|
-
rows: failedCreateRows(failedCreates),
|
|
3888
|
-
next: [{ type: "text", text: facts.fix }, ...mayExistSteps(mayExist, ttlMinutes2)]
|
|
3889
|
-
};
|
|
3890
|
-
}
|
|
3891
|
-
function credentialRejected(credential, data) {
|
|
3892
|
-
const { origin, fix } = rejectedCredentialFacts(credential);
|
|
3893
|
-
const { status, vercelId, ttlMinutes: ttlMinutes2, failedCreates, unpooled, sandboxMayExist: mayExist } = data;
|
|
3894
|
-
return {
|
|
3895
|
-
refused: "credential_rejected",
|
|
3896
|
-
data: { origin, fix, ...data },
|
|
3897
|
-
message: `The Testserver control plane rejected ${rejectedCredentialText(origin)} (HTTP ${status}, x-vercel-id ${vercelId ?? "unknown"}). ${NOT_RUN}`,
|
|
3898
|
-
rows: [...credentialOriginRows(origin), ...unpooledRows(unpooled), ...failedCreateRows(failedCreates)],
|
|
3899
|
-
next: [{ type: "text", text: fix }, ...mayExistSteps(mayExist, ttlMinutes2)]
|
|
3900
|
-
};
|
|
3901
|
-
}
|
|
3902
|
-
function noSandboxes(data) {
|
|
3903
|
-
const { requested, ttlMinutes: ttlMinutes2, failedCreates, sandboxMayExist: mayExist } = data;
|
|
3904
|
-
return {
|
|
3905
|
-
refused: "no_sandboxes",
|
|
3906
|
-
data: { ...data },
|
|
3907
|
-
message: `Got none of the ${requested} Testserver sandboxes asked for: the pool had no usable one, and all ${failedCreates.length} creates failed. ${NOT_RUN}`,
|
|
3908
|
-
rows: [["Failed creates", failedCreates.map(createFailureText)]],
|
|
3909
|
-
...mayExist ? { next: mayExistSteps(mayExist, ttlMinutes2) } : {}
|
|
3910
|
-
};
|
|
3911
|
-
}
|
|
3912
|
-
function noUsableSandboxes(data) {
|
|
3913
|
-
const { requested, build } = data;
|
|
3914
|
-
return {
|
|
3915
|
-
refused: "no_usable_sandboxes",
|
|
3916
|
-
data: { ...data },
|
|
3917
|
-
message: `${requested === 1 ? "Got no Testserver sandbox" : `Got none of the ${requested} Testserver sandboxes asked for`}: the pool has no usable one on ${build}, and with create false the run creates none. ${NOT_RUN}`,
|
|
3918
|
-
next: [
|
|
3919
|
-
{
|
|
3920
|
-
type: "text",
|
|
3921
|
-
text: `Set ${CREATE_KEY_PATH} to true to create Testserver sandboxes, or check the pool with storm ext testserver pool list.`
|
|
3922
|
-
}
|
|
3923
|
-
]
|
|
3924
|
-
};
|
|
3925
|
-
}
|
|
3926
|
-
|
|
3927
|
-
// src/extensions/testserver/release.ts
|
|
3928
|
-
function testserverPoolReleasedText(leased, releaseFailures) {
|
|
3929
|
-
const released = leased.length - releaseFailures.length;
|
|
3930
|
-
return released <= 0 ? void 0 : `released ${released} ${released === 1 ? "lease" : "leases"}`;
|
|
3931
|
-
}
|
|
3932
|
-
function testserverPoolReleaseWarnings(releaseFailures) {
|
|
3933
|
-
return releaseFailures.map(({ path, message }) => ({
|
|
3934
|
-
reason: "release_failed",
|
|
3935
|
-
message: `Couldn't release the lease at ${path}: ${message}. A later run reclaims it once this one has exited.`
|
|
3936
|
-
}));
|
|
3937
|
-
}
|
|
3938
|
-
function testserverPoolReleased(releaseFailures) {
|
|
3939
|
-
return { done: releaseFailures.length === 0 ? ["The run holds no lease."] : [] };
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
// src/extensions/testserver/result.ts
|
|
3943
|
-
function testserverPoolResult(provisioned, options) {
|
|
3944
|
-
const facts = resultFacts(provisioned, options);
|
|
3945
|
-
return { facts, rows: resultRows(facts) };
|
|
3946
|
-
}
|
|
3947
|
-
function resultFacts(provisioned, options) {
|
|
3948
|
-
const { resolution, sandboxes } = provisioned;
|
|
3949
|
-
return {
|
|
3950
|
-
build: {
|
|
3951
|
-
requested: options.build,
|
|
3952
|
-
resolved: resolution.kind === "as-written" ? null : resolution.build,
|
|
3953
|
-
pullRequest: resolution.kind === "pull-request" ? { repo: TESTSERVER_REPO, number: resolution.pr, headSha: resolution.headSha } : null
|
|
3954
|
-
},
|
|
3955
|
-
sandboxes: sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({ testserverUrl, logViewerUrl, origin })),
|
|
3956
|
-
reused: sandboxes.filter((sandbox) => sandbox.origin === "reused").length,
|
|
3957
|
-
created: sandboxes.filter((sandbox) => sandbox.origin === "created").length,
|
|
3958
|
-
failedCreates: failedCreateFacts(provisioned.failedCreates),
|
|
3959
|
-
unpooled: unpooledFacts(provisioned.unpooled),
|
|
3960
|
-
uncreated: provisioned.uncreated === void 0 ? null : {
|
|
3961
|
-
count: provisioned.uncreated.count,
|
|
3962
|
-
source: provisioned.uncreated.failure.source,
|
|
3963
|
-
...describeCredentialFailure(provisioned.uncreated.failure)
|
|
3964
|
-
},
|
|
3965
|
-
notCreated: provisioned.notCreated
|
|
3966
|
-
};
|
|
3967
|
-
}
|
|
3968
|
-
function testserverPoolResultWarnings(facts) {
|
|
3969
|
-
return [
|
|
3970
|
-
...facts.failedCreates.length === 0 ? [] : [
|
|
3971
|
-
{
|
|
3972
|
-
reason: "creates_failed",
|
|
3973
|
-
message: `${facts.failedCreates.length} of ${facts.failedCreates.length + facts.created} creates failed (${facts.failedCreates.map(createFailureText).join("; ")}); the command ran on ${facts.sandboxes.length} Testserver sandboxes.`
|
|
3974
|
-
}
|
|
3975
|
-
],
|
|
3976
|
-
...facts.unpooled.map(({ testserverUrl, message }) => ({
|
|
3977
|
-
reason: "sandbox_not_pooled",
|
|
3978
|
-
message: `Used the Testserver sandbox ${testserverUrl}, but couldn't add it to the pool: ${message}`
|
|
3979
|
-
})),
|
|
3980
|
-
...facts.uncreated === null ? [] : [
|
|
3981
|
-
facts.uncreated.source === "mint" ? {
|
|
3982
|
-
reason: "mint_failed",
|
|
3983
|
-
message: `Couldn't create ${facts.uncreated.count} more Testserver sandboxes: couldn't mint a credential: ${facts.uncreated.cause}. ${facts.uncreated.fix}`
|
|
3984
|
-
} : {
|
|
3985
|
-
reason: "token_request_failed",
|
|
3986
|
-
message: `Couldn't create ${facts.uncreated.count} more Testserver sandboxes: couldn't request a GitHub Actions OIDC token: ${facts.uncreated.cause}. ${facts.uncreated.fix}`
|
|
3987
|
-
}
|
|
3988
|
-
],
|
|
3989
|
-
...facts.notCreated === 0 ? [] : [
|
|
3990
|
-
{
|
|
3991
|
-
reason: "sandboxes_not_created",
|
|
3992
|
-
message: `create is false: ${facts.notCreated} of ${facts.notCreated + facts.sandboxes.length} Testserver sandboxes couldn't be leased, and none were created; the command ran on ${facts.sandboxes.length}.`
|
|
3993
|
-
}
|
|
3994
|
-
]
|
|
3995
|
-
];
|
|
3996
|
-
}
|
|
3997
|
-
function resultRows(facts) {
|
|
3998
|
-
return facts.sandboxes.length === 0 ? [] : [
|
|
3999
|
-
[
|
|
4000
|
-
"Testserver",
|
|
4001
|
-
facts.sandboxes.flatMap(({ testserverUrl, logViewerUrl, origin }) => [
|
|
4002
|
-
`${testserverUrl} (${origin})`,
|
|
4003
|
-
` logs ${logViewerUrl}`
|
|
4004
|
-
])
|
|
4005
|
-
]
|
|
4006
|
-
];
|
|
4007
|
-
}
|
|
4008
|
-
|
|
4009
|
-
// src/extensions/testserver/run-sandbox.ts
|
|
4010
|
-
function testserverConnectionOf(sandboxes) {
|
|
4011
|
-
return { sandboxes: [...new Set(sandboxes.map((sandbox) => sandbox.testserverUrl))].map((url) => ({ url })) };
|
|
4012
|
-
}
|
|
4013
|
-
var STALE_TESTSERVER_VARIABLES = ["TESTSERVER_BASES", "TESTSERVER_BASE"];
|
|
4014
|
-
|
|
4015
|
-
// src/extensions/testserver/lifecycle.ts
|
|
4016
|
-
function testserverPoolLifecycle(world) {
|
|
4017
|
-
return {
|
|
4018
|
-
beforeRun: async ({
|
|
4019
|
-
options
|
|
4020
|
-
}) => {
|
|
4021
|
-
const prepared = await world.pool.prepare();
|
|
4022
|
-
if (!prepared.ok) return poolUnavailable(prepared.failure);
|
|
4023
|
-
return {
|
|
4024
|
-
use: { secrets: {}, needsVercelCredential: options.create, hiddenVariables: STALE_TESTSERVER_VARIABLES }
|
|
4025
|
-
};
|
|
4026
|
-
},
|
|
4027
|
-
acquireForRun: async ({
|
|
4028
|
-
options,
|
|
4029
|
-
credential,
|
|
4030
|
-
take,
|
|
4031
|
-
report,
|
|
4032
|
-
signal
|
|
4033
|
-
}) => {
|
|
4034
|
-
const provisioned = await provision(world, options, createWith(options, credential), signal, report, take);
|
|
4035
|
-
if (provisioned.kind === "canceled") {
|
|
4036
|
-
const { kind: _kind2, ...facts2 } = provisioned;
|
|
4037
|
-
return { canceled: testserverCanceledLines(facts2) };
|
|
4038
|
-
}
|
|
4039
|
-
if (provisioned.kind === "mint-failed") return { mintFailed: provisioned.failed };
|
|
4040
|
-
if (provisioned.kind !== "provisioned") return acquireRefusal(provisioned);
|
|
4041
|
-
const { kind: _kind, ...facts } = provisioned;
|
|
4042
|
-
const sandboxes = facts.sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({
|
|
4043
|
-
testserverUrl,
|
|
4044
|
-
logViewerUrl,
|
|
4045
|
-
origin
|
|
4046
|
-
}));
|
|
4047
|
-
const result = testserverPoolResult(facts, options);
|
|
4048
|
-
for (const { reason, message } of testserverPoolResultWarnings(result.facts))
|
|
4049
|
-
await report.warning(reason, message);
|
|
4050
|
-
return {
|
|
4051
|
-
acquired: {
|
|
4052
|
-
payload: testserverConnectionOf(facts.sandboxes),
|
|
4053
|
-
result,
|
|
4054
|
-
announce: { kind: "acquired", sandboxes },
|
|
4055
|
-
canceled: testserverCanceledLines(testserverCanceledFacts(options, facts))
|
|
4056
|
-
}
|
|
4057
|
-
};
|
|
4058
|
-
},
|
|
4059
|
-
releaseAfterRun: async ({
|
|
4060
|
-
taken,
|
|
4061
|
-
report
|
|
4062
|
-
}) => {
|
|
4063
|
-
const releaseFailures = await releaseLeases(world, taken);
|
|
4064
|
-
const released = testserverPoolReleasedText(taken, releaseFailures);
|
|
4065
|
-
if (released !== void 0) await report.cleanup(released);
|
|
4066
|
-
for (const { reason, message } of testserverPoolReleaseWarnings(releaseFailures))
|
|
4067
|
-
await report.warning(reason, message);
|
|
4068
|
-
return testserverPoolReleased(releaseFailures);
|
|
4069
|
-
}
|
|
4070
|
-
};
|
|
4071
|
-
}
|
|
4072
|
-
function acquireRefusal(refusal) {
|
|
4073
|
-
switch (refusal.kind) {
|
|
4074
|
-
case "pool-unreadable":
|
|
4075
|
-
return poolUnreadable(refusal.failure);
|
|
4076
|
-
case "token-request-failed":
|
|
4077
|
-
return tokenRequestFailed(refusal.failure, {
|
|
4078
|
-
ttlMinutes: refusal.ttlMinutes,
|
|
4079
|
-
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4080
|
-
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4081
|
-
});
|
|
4082
|
-
case "credential-rejected":
|
|
4083
|
-
return credentialRejected(refusal.origin, {
|
|
4084
|
-
status: refusal.failure.status,
|
|
4085
|
-
vercelId: refusal.failure.vercelId ?? null,
|
|
4086
|
-
ttlMinutes: refusal.ttlMinutes,
|
|
4087
|
-
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4088
|
-
unpooled: unpooledFacts(refusal.unpooled),
|
|
4089
|
-
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4090
|
-
});
|
|
4091
|
-
case "no-sandboxes":
|
|
4092
|
-
return noSandboxes({
|
|
4093
|
-
requested: refusal.requested,
|
|
4094
|
-
ttlMinutes: refusal.ttlMinutes,
|
|
4095
|
-
failedCreates: failedCreateFacts(refusal.failedCreates),
|
|
4096
|
-
sandboxMayExist: refusal.failedCreates.some(mayLeaveSandbox)
|
|
4097
|
-
});
|
|
4098
|
-
case "no-usable-sandboxes":
|
|
4099
|
-
return noUsableSandboxes({
|
|
4100
|
-
requested: refusal.requested,
|
|
4101
|
-
build: "resolvedBuild" in refusal.match ? refusal.match.resolvedBuild : refusal.match.requestedBuild
|
|
4102
|
-
});
|
|
4103
|
-
case "pull-request-unreadable":
|
|
4104
|
-
case "pr-builds-unlisted":
|
|
4105
|
-
case "pr-build-not-ready":
|
|
4106
|
-
case "pr-build-expired":
|
|
4107
|
-
return prBuildRefusal(refusal, "The command didn't run.");
|
|
4108
|
-
}
|
|
4109
|
-
}
|
|
4110
|
-
|
|
4111
|
-
// src/extensions/testserver/pull-request/live/github-rest.ts
|
|
4112
|
-
import { z as z9 } from "zod";
|
|
4113
|
-
var errorSchema = z9.object({ message: z9.string() });
|
|
4114
|
-
function headers(token) {
|
|
4115
|
-
return {
|
|
4116
|
-
accept: "application/vnd.github+json",
|
|
4117
|
-
authorization: `Bearer ${token}`,
|
|
4118
|
-
"x-github-api-version": "2022-11-28",
|
|
4119
|
-
"user-agent": "storm"
|
|
4120
|
-
};
|
|
4121
|
-
}
|
|
4122
|
-
function hideToken(text, token) {
|
|
4123
|
-
return token === "" ? text : text.replaceAll(token, "<token>");
|
|
4124
|
-
}
|
|
4125
|
-
async function getJson(options, token, path, schema) {
|
|
4126
|
-
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
4127
|
-
try {
|
|
4128
|
-
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
4129
|
-
const text = await response.text();
|
|
4130
|
-
if (response.status < 200 || response.status >= 300)
|
|
4131
|
-
return {
|
|
4132
|
-
ok: false,
|
|
4133
|
-
failure: statusFailure(response.status, hideToken(githubMessage(text, response.status), token))
|
|
4134
|
-
};
|
|
4135
|
-
let json;
|
|
4136
|
-
try {
|
|
4137
|
-
json = JSON.parse(text);
|
|
4138
|
-
} catch {
|
|
4139
|
-
return { ok: false, failure: { kind: "malformed", detail: "the answer isn't JSON" } };
|
|
4140
|
-
}
|
|
4141
|
-
const parsed = schema.safeParse(json);
|
|
4142
|
-
if (!parsed.success) {
|
|
4143
|
-
const issue = parsed.error.issues[0];
|
|
4144
|
-
const where2 = issue === void 0 || issue.path.length === 0 ? "the answer" : issue.path.join(".");
|
|
4145
|
-
return {
|
|
4146
|
-
ok: false,
|
|
4147
|
-
failure: { kind: "malformed", detail: hideToken(`${where2}: ${issue?.message ?? "unexpected"}`, token) }
|
|
4148
|
-
};
|
|
4149
|
-
}
|
|
4150
|
-
return { ok: true, value: parsed.data };
|
|
4151
|
-
} catch (error) {
|
|
4152
|
-
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
4153
|
-
}
|
|
4154
|
-
}
|
|
4155
|
-
async function getRedirectedText(options, token, path) {
|
|
4156
|
-
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
4157
|
-
try {
|
|
4158
|
-
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
4159
|
-
if (response.status >= 200 && response.status < 300) return { ok: true, value: await response.text() };
|
|
4160
|
-
const location = response.headers.get("location");
|
|
4161
|
-
if (response.status < 300 || response.status >= 400 || location === null) {
|
|
4162
|
-
const text2 = await response.text();
|
|
4163
|
-
return {
|
|
4164
|
-
ok: false,
|
|
4165
|
-
failure: statusFailure(response.status, hideToken(githubMessage(text2, response.status), token))
|
|
4166
|
-
};
|
|
4167
|
-
}
|
|
4168
|
-
await response.body?.cancel().catch(() => {
|
|
4169
|
-
});
|
|
4170
|
-
const redirected = await fetch(location, { redirect: "follow", signal });
|
|
4171
|
-
const text = await redirected.text();
|
|
4172
|
-
if (!redirected.ok) return { ok: false, failure: statusFailure(redirected.status, `HTTP ${redirected.status}`) };
|
|
4173
|
-
return { ok: true, value: text };
|
|
4174
|
-
} catch (error) {
|
|
4175
|
-
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
4176
|
-
}
|
|
4177
|
-
}
|
|
4178
|
-
function statusFailure(status, message) {
|
|
4179
|
-
if (status === 404) return { kind: "not-found", status };
|
|
4180
|
-
if (status === 401 || status === 403) return { kind: "rejected", status, message };
|
|
4181
|
-
return { kind: "http-error", status, message };
|
|
4182
|
-
}
|
|
4183
|
-
function githubMessage(text, status) {
|
|
4184
|
-
try {
|
|
4185
|
-
const parsed = errorSchema.safeParse(JSON.parse(text));
|
|
4186
|
-
if (parsed.success) return parsed.data.message;
|
|
4187
|
-
} catch {
|
|
4188
|
-
}
|
|
4189
|
-
return `HTTP ${status}`;
|
|
4190
|
-
}
|
|
4191
|
-
function thrownFailure(error, signal, options, token) {
|
|
4192
|
-
if (signal.aborted) return { kind: "timeout", seconds: options.timeoutMs / 1e3 };
|
|
4193
|
-
return { kind: "connect-failed", code: hideToken(errorCode2(error), token) };
|
|
4194
|
-
}
|
|
4195
|
-
function errorCode2(error) {
|
|
4196
|
-
if (!(error instanceof Error)) return String(error);
|
|
4197
|
-
const cause = error.cause;
|
|
4198
|
-
const code = typeof cause === "object" && cause !== null ? cause.code : void 0;
|
|
4199
|
-
return typeof code === "string" ? code : error.message;
|
|
4200
|
-
}
|
|
4201
|
-
|
|
4202
|
-
// src/extensions/testserver/pull-request/live/github-token-gateway.ts
|
|
4203
|
-
import { execFile as execFile3 } from "node:child_process";
|
|
4204
|
-
var GH_TOKEN_TIMEOUT_MS = 5e3;
|
|
4205
|
-
function liveGitHubTokenGateway(options) {
|
|
4206
|
-
return {
|
|
4207
|
-
token: async () => {
|
|
4208
|
-
for (const origin of ["GITHUB_TOKEN", "GH_TOKEN"]) {
|
|
4209
|
-
const token2 = options.env[origin]?.trim();
|
|
4210
|
-
if (token2 !== void 0 && token2 !== "") return { token: token2, origin };
|
|
4211
|
-
}
|
|
4212
|
-
const token = await ghAuthToken(options.env);
|
|
4213
|
-
return token === void 0 ? void 0 : { token, origin: "gh auth token" };
|
|
4214
|
-
}
|
|
4215
|
-
};
|
|
4216
|
-
}
|
|
4217
|
-
function ghAuthToken(env) {
|
|
4218
|
-
return new Promise((resolve) => {
|
|
4219
|
-
try {
|
|
4220
|
-
execFile3(
|
|
4221
|
-
"gh",
|
|
4222
|
-
["auth", "token", "--hostname", "github.com"],
|
|
4223
|
-
{ env: { ...env }, timeout: GH_TOKEN_TIMEOUT_MS, encoding: "utf8" },
|
|
4224
|
-
(error, stdout) => {
|
|
4225
|
-
const token = typeof stdout === "string" ? stdout.trim() : "";
|
|
4226
|
-
resolve(error === null && token !== "" ? token : void 0);
|
|
4227
|
-
}
|
|
4228
|
-
);
|
|
4229
|
-
} catch {
|
|
4230
|
-
resolve(void 0);
|
|
4231
|
-
}
|
|
4232
|
-
});
|
|
4233
|
-
}
|
|
4234
|
-
|
|
4235
|
-
// src/extensions/testserver/pull-request/live/pull-request-gateway.ts
|
|
4236
|
-
import { z as z10 } from "zod";
|
|
4237
|
-
var pullSchema = z10.object({
|
|
4238
|
-
head: z10.object({ sha: z10.string().regex(/^[0-9a-f]{40}$/), ref: z10.string().min(1) }),
|
|
4239
|
-
state: z10.enum(["open", "closed"]),
|
|
4240
|
-
merged: z10.boolean()
|
|
4241
|
-
});
|
|
4242
|
-
function livePullRequestGateway(options) {
|
|
4243
|
-
return {
|
|
4244
|
-
head: async ({ repo, number, token }) => {
|
|
4245
|
-
const answered = await getJson(options, token, `repos/${repoPath(repo)}/pulls/${number}`, pullSchema);
|
|
4246
|
-
if (!answered.ok) return answered;
|
|
4247
|
-
const { head: head2, state: state2, merged } = answered.value;
|
|
4248
|
-
return { ok: true, head: { headSha: head2.sha, headRef: head2.ref, state: state2, merged } };
|
|
4249
|
-
}
|
|
4250
|
-
};
|
|
4251
|
-
}
|
|
4252
|
-
function repoPath(repo) {
|
|
4253
|
-
return repo.split("/").map(encodeURIComponent).join("/");
|
|
4254
|
-
}
|
|
4255
|
-
|
|
4256
|
-
// src/extensions/testserver/pull-request/live/testserver-workflow-gateway.ts
|
|
4257
|
-
import { z as z11 } from "zod";
|
|
4258
|
-
var TESTSERVER_WORKFLOW = "testserver-bundle-publish.yml";
|
|
4259
|
-
var BUNDLE_JOB = "Bundle & Publish";
|
|
4260
|
-
var RUNS_LISTED = 30;
|
|
4261
|
-
var BUNDLE_LINE = /📦 Bundle will be: builds\/pr-([1-9][0-9]*)\/([^\s/]+)/;
|
|
4262
|
-
var runsSchema = z11.object({
|
|
4263
|
-
workflow_runs: z11.array(
|
|
4264
|
-
z11.object({
|
|
4265
|
-
id: z11.number(),
|
|
4266
|
-
head_sha: z11.string().regex(/^[0-9a-f]{40}$/),
|
|
4267
|
-
created_at: z11.string().min(1)
|
|
4268
|
-
})
|
|
4269
|
-
)
|
|
4270
|
-
});
|
|
4271
|
-
var jobsSchema = z11.object({
|
|
4272
|
-
jobs: z11.array(z11.object({ id: z11.number(), name: z11.string(), conclusion: z11.string().nullable() }))
|
|
4273
|
-
});
|
|
4274
|
-
function liveTestserverWorkflowGateway(options) {
|
|
4275
|
-
return {
|
|
4276
|
-
runs: async ({ repo, branch, token }) => {
|
|
4277
|
-
const query = new URLSearchParams({ event: "pull_request", branch, per_page: String(RUNS_LISTED) });
|
|
4278
|
-
const answered = await getJson(
|
|
4279
|
-
options,
|
|
4280
|
-
token,
|
|
4281
|
-
`repos/${repoPath(repo)}/actions/workflows/${TESTSERVER_WORKFLOW}/runs?${query.toString()}`,
|
|
4282
|
-
runsSchema
|
|
4283
|
-
);
|
|
4284
|
-
if (!answered.ok) return answered;
|
|
4285
|
-
const runs = answered.value.workflow_runs.map((run) => ({
|
|
4286
|
-
id: run.id,
|
|
4287
|
-
headSha: run.head_sha,
|
|
4288
|
-
createdAt: run.created_at
|
|
4289
|
-
}));
|
|
4290
|
-
return { ok: true, runs };
|
|
4291
|
-
},
|
|
4292
|
-
publishedBuild: async ({ repo, runId, token }) => {
|
|
4293
|
-
const jobs = await getJson(options, token, `repos/${repoPath(repo)}/actions/runs/${runId}/jobs`, jobsSchema);
|
|
4294
|
-
if (!jobs.ok) return jobs;
|
|
4295
|
-
const job = jobs.value.jobs.find(({ name: name2 }) => name2 === BUNDLE_JOB);
|
|
4296
|
-
if (job === void 0 || job.conclusion !== "success") return { ok: true, build: void 0 };
|
|
4297
|
-
const log = await getRedirectedText(
|
|
4298
|
-
{ origin: options.origin, timeoutMs: options.logTimeoutMs },
|
|
4299
|
-
token,
|
|
4300
|
-
`repos/${repoPath(repo)}/actions/jobs/${job.id}/logs`
|
|
4301
|
-
);
|
|
4302
|
-
if (!log.ok) return log;
|
|
4303
|
-
const match = BUNDLE_LINE.exec(log.value);
|
|
4304
|
-
const [, pr, name] = match ?? [];
|
|
4305
|
-
return { ok: true, build: pr === void 0 || name === void 0 ? void 0 : { pr: Number(pr), name } };
|
|
4306
|
-
}
|
|
4307
|
-
};
|
|
4308
|
-
}
|
|
4309
|
-
|
|
4310
|
-
// src/extensions/testserver/live/world.ts
|
|
4311
|
-
var TESTSERVER_ORIGIN = "https://testserver.vercel.sh";
|
|
4312
|
-
var GITHUB_API_ORIGIN = "https://api.github.com";
|
|
4313
|
-
function liveTestserverWorld(supplies) {
|
|
4314
|
-
const { stateDirectory } = supplies;
|
|
4315
|
-
return {
|
|
4316
|
-
controlPlane: liveControlPlaneGateway({
|
|
4317
|
-
origin: TESTSERVER_ORIGIN,
|
|
4318
|
-
streamTimeoutMs: 18e4,
|
|
4319
|
-
buildsTimeoutMs: 1e4
|
|
4320
|
-
}),
|
|
4321
|
-
healthChecks: liveHealthCheckGateway({ timeoutMs: 5e3 }),
|
|
4322
|
-
pool: stateDirectory.ok ? livePoolStoreGateway({ directory: stateDirectory.directory }) : unavailablePoolStoreGateway(stateDirectory.pattern, stateDirectory.reason),
|
|
4323
|
-
pullRequests: livePullRequestGateway({ origin: GITHUB_API_ORIGIN, timeoutMs: 1e4 }),
|
|
4324
|
-
testserverWorkflow: liveTestserverWorkflowGateway({
|
|
4325
|
-
origin: GITHUB_API_ORIGIN,
|
|
4326
|
-
timeoutMs: 1e4,
|
|
4327
|
-
logTimeoutMs: 3e4
|
|
4328
|
-
}),
|
|
4329
|
-
githubToken: liveGitHubTokenGateway({ env: supplies.env }),
|
|
4330
|
-
timer: supplies.timer,
|
|
4331
|
-
clock: supplies.clock
|
|
4332
|
-
};
|
|
4333
|
-
}
|
|
4334
|
-
|
|
4335
|
-
// src/extensions/testserver/presentation.ts
|
|
4336
|
-
function line(text) {
|
|
4337
|
-
return { lane: "testserver", text };
|
|
4338
|
-
}
|
|
4339
|
-
function poolUpkeepTexts(report) {
|
|
4340
|
-
return [
|
|
4341
|
-
...report.reclaimed.length === 0 ? [] : [`reclaimed ${count(report.reclaimed.length, "stale lease")}`],
|
|
4342
|
-
...report.dropped.length === 0 ? [] : [`dropped ${count(report.dropped.length, "Testserver sandbox")} from the pool`],
|
|
4343
|
-
...report.storeFailures.map(({ path, message }) => `a pool operation failed on ${path}: ${message}`)
|
|
4344
|
-
];
|
|
4345
|
-
}
|
|
4346
|
-
function createFinishedText(event) {
|
|
4347
|
-
const which = `create ${event.index + 1} of ${event.count}`;
|
|
4348
|
-
const { outcome } = event;
|
|
4349
|
-
switch (outcome.kind) {
|
|
4350
|
-
case "pooled":
|
|
4351
|
-
return `${which} done: ${outcome.entry.testserverUrl}`;
|
|
4352
|
-
case "pool-write-failed":
|
|
4353
|
-
return `${which} done: ${outcome.entry.testserverUrl}, not added to the pool`;
|
|
4354
|
-
case "create-failed":
|
|
4355
|
-
return `${which} failed: ${describeCreateFailure(outcome.failure).text}`;
|
|
4356
|
-
}
|
|
4357
|
-
}
|
|
4358
|
-
function createProgressText(event) {
|
|
4359
|
-
return `create ${event.index + 1} of ${event.count}: ${event.message}`;
|
|
4360
|
-
}
|
|
4361
|
-
function unresolvedBuildText(event) {
|
|
4362
|
-
return `couldn't resolve ${event.channel} (${unresolvedWhy(event.reason)}); using Testserver sandboxes requested as ${event.channel}`;
|
|
4363
|
-
}
|
|
4364
|
-
function oldChannelResolutionText(event) {
|
|
4365
|
-
return event.ageMinutes < 0 ? `using ${event.channel}'s channel resolution, recorded later than now (create is false)` : `using ${event.channel}'s channel resolution from ${age(event.ageMinutes)} ago (create is false)`;
|
|
4366
|
-
}
|
|
4367
|
-
function prBuildResolvedText(event) {
|
|
4368
|
-
const pooled = event.from === "pool" ? " (from the pool)" : "";
|
|
4369
|
-
const merged = event.merged ? " (merged; latest_main or stable may have it)" : "";
|
|
4370
|
-
return `Build: ${TESTSERVER_REPO}#${event.pr} at ${shortSha(event.headSha)} \u2192 ${event.build}${pooled}${merged}`;
|
|
4371
|
-
}
|
|
4372
|
-
function unresolvedWhy(reason) {
|
|
4373
|
-
switch (reason.kind) {
|
|
4374
|
-
case "credential-failed": {
|
|
4375
|
-
const { cause } = describeCredentialFailure(reason.failure);
|
|
4376
|
-
return reason.failure.source === "mint" ? `couldn't mint a credential: ${cause}` : `couldn't request a GitHub Actions OIDC token: ${cause}`;
|
|
4377
|
-
}
|
|
4378
|
-
case "builds-failed":
|
|
4379
|
-
return `GET /builds failed: ${reason.failure.kind}`;
|
|
4380
|
-
case "no-build":
|
|
4381
|
-
return "the Testserver control plane names no build for it";
|
|
4382
|
-
case "not-recorded":
|
|
4383
|
-
return "no channel resolution is recorded, and with create false the run doesn't ask the Testserver control plane";
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
function age(minutes) {
|
|
4387
|
-
if (minutes < 60) return `${minutes}m`;
|
|
4388
|
-
if (minutes < 48 * 60) return `${Math.floor(minutes / 60)}h`;
|
|
4389
|
-
return `${Math.floor(minutes / (24 * 60))}d`;
|
|
4390
|
-
}
|
|
4391
|
-
function count(n, noun) {
|
|
4392
|
-
const plural = { "stale lease": "stale leases", "Testserver sandbox": "Testserver sandboxes" }[noun];
|
|
4393
|
-
return `${n} ${n === 1 ? noun : plural}`;
|
|
4394
|
-
}
|
|
4395
|
-
function onBuild(testserver) {
|
|
4396
|
-
return testserver.build === void 0 ? "" : ` on ${testserver.build}`;
|
|
4397
|
-
}
|
|
4398
|
-
function reusedCount(testserver) {
|
|
4399
|
-
return testserver.sandboxes.filter(({ origin }) => origin === "reused").length;
|
|
4400
|
-
}
|
|
4401
|
-
function originCounts(testserver) {
|
|
4402
|
-
const reused = reusedCount(testserver);
|
|
4403
|
-
return `${reused} reused, ${testserver.sandboxes.length - reused} created`;
|
|
4404
|
-
}
|
|
4405
|
-
function leasingText(testserver) {
|
|
4406
|
-
return testserver.requested === void 0 ? "resolving the build" : `leasing ${testserver.requested}${onBuild(testserver)}`;
|
|
4407
|
-
}
|
|
4408
|
-
function createsText(creates, paint) {
|
|
4409
|
-
const failed = creates.failed === 0 ? "" : ` \xB7 ${paint.failed(`${creates.failed} failed`)}`;
|
|
4410
|
-
return `creating ${creates.count} \xB7 ${creates.started} started \xB7 ${creates.finished - creates.failed} done${failed}`;
|
|
4411
|
-
}
|
|
4412
|
-
function creating(testserver) {
|
|
4413
|
-
const { creates } = testserver;
|
|
4414
|
-
return creates !== void 0 && creates.finished < creates.count && testserver.status === "running";
|
|
4415
|
-
}
|
|
4416
|
-
function testserverOutcome(testserver) {
|
|
4417
|
-
const counts = `${originCounts(testserver)}${onBuild(testserver)}`;
|
|
4418
|
-
return testserver.status === "done" ? counts : `${counts} \xB7 ${testserver.status}`;
|
|
4419
|
-
}
|
|
4420
|
-
function sandboxLines(testserver, draw) {
|
|
4421
|
-
return testserver.sandboxes.map(
|
|
4422
|
-
({ testserverUrl, logViewerUrl }) => draw.line(` ${sandboxName(testserverUrl)} ${draw.paint.faint("logs")} ${logViewerUrl}`)
|
|
4423
|
-
);
|
|
4424
|
-
}
|
|
4425
|
-
function sandboxName(testserverUrl) {
|
|
4426
|
-
try {
|
|
4427
|
-
return new URL(testserverUrl).hostname.split(".")[0] ?? testserverUrl;
|
|
4428
|
-
} catch {
|
|
4429
|
-
return testserverUrl;
|
|
4430
|
-
}
|
|
4431
|
-
}
|
|
4432
|
-
var testserverPoolDrawing = {
|
|
4433
|
-
plain: ({ verbose, seconds }) => {
|
|
4434
|
-
let leasingAt;
|
|
4435
|
-
return (event, now) => {
|
|
4436
|
-
switch (event.kind) {
|
|
4437
|
-
case "build-unresolved":
|
|
4438
|
-
return [line(unresolvedBuildText(event))];
|
|
4439
|
-
case "old-channel-resolution":
|
|
4440
|
-
return [line(oldChannelResolutionText(event))];
|
|
4441
|
-
case "pr-build-resolved":
|
|
4442
|
-
return [line(prBuildResolvedText(event))];
|
|
4443
|
-
case "leasing":
|
|
4444
|
-
leasingAt = now;
|
|
4445
|
-
return [];
|
|
4446
|
-
case "leased": {
|
|
4447
|
-
const { report, requested } = event;
|
|
4448
|
-
const build = "resolvedBuild" in event.match ? event.match.resolvedBuild : event.match.requestedBuild;
|
|
4449
|
-
return [
|
|
4450
|
-
...poolUpkeepTexts(report).map(line),
|
|
4451
|
-
line(
|
|
4452
|
-
`leased ${report.leased.length} of ${count(requested, "Testserver sandbox")} from the pool on ${build} (${seconds(now - (leasingAt ?? now))})`
|
|
4453
|
-
)
|
|
4454
|
-
];
|
|
4455
|
-
}
|
|
4456
|
-
case "creating":
|
|
4457
|
-
return [line(`creating ${count(event.count, "Testserver sandbox")} on ${event.build}\u2026`)];
|
|
4458
|
-
case "create-started":
|
|
4459
|
-
return [line(`create ${event.index + 1} of ${event.count} started`)];
|
|
4460
|
-
case "create-progress":
|
|
4461
|
-
return verbose ? [line(createProgressText(event))] : [];
|
|
4462
|
-
case "create-finished":
|
|
4463
|
-
return [line(createFinishedText(event))];
|
|
4464
|
-
// The Testserver sandboxes the run uses, reused first, just before its command starts.
|
|
4465
|
-
case "acquired":
|
|
4466
|
-
return event.sandboxes.map(
|
|
4467
|
-
({ testserverUrl, logViewerUrl, origin }) => line(`${testserverUrl} logs ${logViewerUrl} (${origin})`)
|
|
4468
|
-
);
|
|
4469
|
-
}
|
|
4470
|
-
};
|
|
4471
|
-
},
|
|
4472
|
-
notices: (event, { verbose }) => {
|
|
4473
|
-
switch (event.kind) {
|
|
4474
|
-
case "build-unresolved":
|
|
4475
|
-
return [line(unresolvedBuildText(event))];
|
|
4476
|
-
case "old-channel-resolution":
|
|
4477
|
-
return [line(oldChannelResolutionText(event))];
|
|
4478
|
-
case "pr-build-resolved":
|
|
4479
|
-
return [line(prBuildResolvedText(event))];
|
|
4480
|
-
case "leased":
|
|
4481
|
-
return poolUpkeepTexts(event.report).map(line);
|
|
4482
|
-
case "create-finished":
|
|
4483
|
-
return event.outcome.kind === "create-failed" ? [line(createFinishedText(event))] : [];
|
|
4484
|
-
case "create-progress":
|
|
4485
|
-
return verbose ? [line(createProgressText(event))] : [];
|
|
4486
|
-
case "leasing":
|
|
4487
|
-
case "creating":
|
|
4488
|
-
case "create-started":
|
|
4489
|
-
// The live view draws the sandbox list from the lane.
|
|
4490
|
-
case "acquired":
|
|
4491
|
-
return [];
|
|
4492
|
-
}
|
|
4493
|
-
},
|
|
4494
|
-
label: "testserver-setup",
|
|
4495
|
-
steps: ["lease", "create"],
|
|
4496
|
-
live: (testserver, draw) => ({
|
|
4497
|
-
text: testserver.status !== "running" ? testserverOutcome(testserver) : testserver.creates === void 0 ? leasingText(testserver) : `${reusedCount(testserver)} reused, creating ${testserver.creates.count}${onBuild(testserver)}`,
|
|
4498
|
-
...creating(testserver) && testserver.creates !== void 0 ? { detail: createsText(testserver.creates, draw.paint) } : {}
|
|
4499
|
-
}),
|
|
4500
|
-
record: (testserver, draw) => ({ text: testserverOutcome(testserver), lines: sandboxLines(testserver, draw) })
|
|
4501
|
-
};
|
|
4502
|
-
|
|
4503
|
-
// src/extensions/testserver/progress.ts
|
|
4504
|
-
var testserverPoolProgress = {
|
|
4505
|
-
lane: "testserver",
|
|
4506
|
-
...testserverPoolDrawing,
|
|
4507
|
-
start: (startedAt) => ({
|
|
4508
|
-
status: "running",
|
|
4509
|
-
startedAt,
|
|
4510
|
-
endedAt: void 0,
|
|
4511
|
-
build: void 0,
|
|
4512
|
-
requested: void 0,
|
|
4513
|
-
sandboxes: [],
|
|
4514
|
-
creates: void 0,
|
|
4515
|
-
steps: { lease: void 0, create: void 0 }
|
|
4516
|
-
}),
|
|
4517
|
-
apply: (testserver, event, at) => applyTestserverEvent(testserver, event, at),
|
|
4518
|
-
ended: (testserver, outcome, at) => {
|
|
4519
|
-
const status = outcome === "ready" ? "done" : outcome;
|
|
4520
|
-
const settle = (span) => settled(span, outcome, status, at);
|
|
4521
|
-
return {
|
|
4522
|
-
...testserver,
|
|
4523
|
-
status,
|
|
4524
|
-
endedAt: at,
|
|
4525
|
-
steps: { lease: settle(testserver.steps.lease), create: settle(testserver.steps.create) }
|
|
4526
|
-
};
|
|
4527
|
-
},
|
|
4528
|
-
row: (testserver) => {
|
|
4529
|
-
const reused = testserver.sandboxes.filter(({ origin }) => origin === "reused").length;
|
|
4530
|
-
const { lease, create } = testserver.steps;
|
|
4531
|
-
return {
|
|
4532
|
-
steps: [
|
|
4533
|
-
...lease === void 0 ? [] : [{ name: "lease", span: lease }],
|
|
4534
|
-
...create === void 0 ? [] : [{ name: "create", span: create }]
|
|
4535
|
-
],
|
|
4536
|
-
sandboxes: { reused, created: testserver.sandboxes.length - reused }
|
|
4537
|
-
};
|
|
4538
|
-
}
|
|
4539
|
-
};
|
|
4540
|
-
function applyTestserverEvent(testserver, event, at) {
|
|
4541
|
-
switch (event.kind) {
|
|
4542
|
-
// Resolving the build is part of the lane, but changes nothing it shows.
|
|
4543
|
-
case "build-unresolved":
|
|
4544
|
-
case "old-channel-resolution":
|
|
4545
|
-
case "pr-build-resolved":
|
|
4546
|
-
case "create-progress":
|
|
4547
|
-
return testserver;
|
|
4548
|
-
// The run acquired the pool: the lane holds the sandbox list.
|
|
4549
|
-
case "acquired":
|
|
4550
|
-
return {
|
|
4551
|
-
...testserver,
|
|
4552
|
-
sandboxes: event.sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({
|
|
4553
|
-
testserverUrl,
|
|
4554
|
-
logViewerUrl,
|
|
4555
|
-
origin
|
|
4556
|
-
}))
|
|
4557
|
-
};
|
|
4558
|
-
case "leasing":
|
|
4559
|
-
return {
|
|
4560
|
-
...testserver,
|
|
4561
|
-
build: buildName(event.match),
|
|
4562
|
-
requested: event.requested,
|
|
4563
|
-
steps: { ...testserver.steps, lease: { status: "running", startedAt: at, endedAt: void 0 } }
|
|
4564
|
-
};
|
|
4565
|
-
case "leased":
|
|
4566
|
-
return {
|
|
4567
|
-
...testserver,
|
|
4568
|
-
sandboxes: event.report.leased.map(({ entry }) => ({
|
|
4569
|
-
testserverUrl: entry.testserverUrl,
|
|
4570
|
-
logViewerUrl: entry.logViewerUrl,
|
|
4571
|
-
origin: "reused"
|
|
4572
|
-
})),
|
|
4573
|
-
steps: { ...testserver.steps, lease: ended(testserver.steps.lease, "done", at) }
|
|
4574
|
-
};
|
|
4575
|
-
case "creating":
|
|
4576
|
-
return {
|
|
4577
|
-
...testserver,
|
|
4578
|
-
creates: { count: event.count, started: 0, finished: 0, failed: 0 },
|
|
4579
|
-
steps: { ...testserver.steps, create: { status: "running", startedAt: at, endedAt: void 0 } }
|
|
4580
|
-
};
|
|
4581
|
-
case "create-started":
|
|
4582
|
-
return {
|
|
4583
|
-
...testserver,
|
|
4584
|
-
creates: testserver.creates === void 0 ? void 0 : { ...testserver.creates, started: testserver.creates.started + 1 }
|
|
4585
|
-
};
|
|
4586
|
-
case "create-finished": {
|
|
4587
|
-
const { outcome } = event;
|
|
4588
|
-
const creates = testserver.creates === void 0 ? void 0 : {
|
|
4589
|
-
...testserver.creates,
|
|
4590
|
-
finished: testserver.creates.finished + 1,
|
|
4591
|
-
failed: testserver.creates.failed + (outcome.kind === "create-failed" ? 1 : 0)
|
|
4592
|
-
};
|
|
4593
|
-
const create = testserver.steps.create;
|
|
4594
|
-
return {
|
|
4595
|
-
...testserver,
|
|
4596
|
-
sandboxes: outcome.kind === "create-failed" ? testserver.sandboxes : [
|
|
4597
|
-
...testserver.sandboxes,
|
|
4598
|
-
{
|
|
4599
|
-
testserverUrl: outcome.entry.testserverUrl,
|
|
4600
|
-
logViewerUrl: outcome.entry.logViewerUrl,
|
|
4601
|
-
origin: "created"
|
|
4602
|
-
}
|
|
4603
|
-
],
|
|
4604
|
-
creates,
|
|
4605
|
-
steps: {
|
|
4606
|
-
...testserver.steps,
|
|
4607
|
-
// The create step ends with the last create; until then it runs, its end at the latest create's.
|
|
4608
|
-
create: create === void 0 ? void 0 : {
|
|
4609
|
-
...create,
|
|
4610
|
-
endedAt: at,
|
|
4611
|
-
status: creates !== void 0 && creates.finished >= creates.count ? "done" : create.status
|
|
4612
|
-
}
|
|
4613
|
-
}
|
|
4614
|
-
};
|
|
4615
|
-
}
|
|
4616
|
-
}
|
|
4617
|
-
}
|
|
4618
|
-
function settled(span, outcome, status, at) {
|
|
4619
|
-
return outcome === "ready" || span === void 0 || span.status !== "running" ? span : ended(span, status, at);
|
|
4620
|
-
}
|
|
4621
|
-
function ended(span, status, at) {
|
|
4622
|
-
return span === void 0 ? void 0 : { ...span, status, endedAt: at };
|
|
4623
|
-
}
|
|
4624
|
-
function buildName(match) {
|
|
4625
|
-
return "resolvedBuild" in match ? match.resolvedBuild : match.requestedBuild;
|
|
4626
|
-
}
|
|
4627
|
-
|
|
4628
|
-
// src/extensions/testserver/definition.ts
|
|
4629
|
-
var NAME = TESTSERVER_POOL_NAME;
|
|
4630
|
-
var testserverPoolDefinition = defineResource({
|
|
4631
|
-
name: NAME,
|
|
4632
|
-
flagPrefix: "testserver",
|
|
4633
|
-
options: testserverPoolRules,
|
|
4634
|
-
check: ({ minTimeLeft, ttl, create }) => {
|
|
4635
|
-
if (!create.value)
|
|
4636
|
-
return ttl.source === "flag" ? [
|
|
4637
|
-
{
|
|
4638
|
-
option: "ttl",
|
|
4639
|
-
problem: `doesn't apply with ${optionKeyPath(NAME, "create")}=false, which creates no Testserver sandbox`,
|
|
4640
|
-
involves: ["ttl", "create"]
|
|
4641
|
-
}
|
|
4642
|
-
] : [];
|
|
4643
|
-
if (ttlMinutes({ ttl: ttl.value }) > minTimeLeftMinutes({ minTimeLeft: minTimeLeft.value })) return [];
|
|
4644
|
-
const problem2 = ttl.source === "default" && minTimeLeft.source !== "default" ? {
|
|
4645
|
-
option: "minTimeLeft",
|
|
4646
|
-
problem: `must be shorter than ${optionKeyPath(NAME, "ttl")} (${ttl.value}), not ${minTimeLeft.value}`,
|
|
4647
|
-
involves: ["minTimeLeft", "ttl"]
|
|
4648
|
-
} : {
|
|
4649
|
-
option: "ttl",
|
|
4650
|
-
problem: `must be longer than ${optionKeyPath(NAME, "minTimeLeft")} (${minTimeLeft.value}), not ${ttl.value}`,
|
|
4651
|
-
involves: ["ttl", "minTimeLeft"]
|
|
4652
|
-
};
|
|
4653
|
-
return [problem2];
|
|
4654
|
-
},
|
|
4655
|
-
// Not the extension's own: the SDK's Testserver connection (`src/sdk/testserver/connection.ts`), its name and payload
|
|
4656
|
-
// check, which the Vitest adapter reads too. Every other value here is the extension's (`ResourceSpec`).
|
|
4657
|
-
payload: testserverConnection,
|
|
4658
|
-
world: liveTestserverWorld,
|
|
4659
|
-
lifecycle: testserverPoolLifecycle,
|
|
4660
|
-
progress: testserverPoolProgress
|
|
4661
|
-
});
|
|
4662
|
-
|
|
4663
3320
|
export {
|
|
4664
3321
|
liveGitHubActionsTokenGateway,
|
|
4665
3322
|
liveCredentialGateway,
|
|
4666
|
-
mintSource,
|
|
4667
|
-
obtainedSource,
|
|
4668
3323
|
credentialSourceFor,
|
|
4669
3324
|
mintTargetText,
|
|
4670
3325
|
credentialErrors,
|
|
@@ -4682,6 +3337,7 @@ export {
|
|
|
4682
3337
|
parseTestEvent,
|
|
4683
3338
|
redactSecrets,
|
|
4684
3339
|
lineSplitter,
|
|
3340
|
+
runStepTakesSecret,
|
|
4685
3341
|
liveRunnerSandboxGateway,
|
|
4686
3342
|
liveRunnerTerminal,
|
|
4687
3343
|
localUserName,
|
|
@@ -4689,14 +3345,10 @@ export {
|
|
|
4689
3345
|
liveRunnerSnapshotCacheGateway,
|
|
4690
3346
|
unavailableRunnerSnapshotCacheGateway,
|
|
4691
3347
|
prepareRunner,
|
|
3348
|
+
SANDBOX_TEST_EVENTS_PATH,
|
|
4692
3349
|
RUNNER_SECRET_MIN_LENGTH,
|
|
4693
3350
|
readRunnerSecrets,
|
|
4694
|
-
|
|
4695
|
-
SANDBOX_TEST_EVENTS_PATH,
|
|
4696
|
-
runCommandInSandbox,
|
|
4697
|
-
keptMs,
|
|
4698
|
-
runnerSandboxScope,
|
|
4699
|
-
saveBranchSnapshot,
|
|
3351
|
+
openRunnerSession,
|
|
4700
3352
|
CONFIG_FILE_NAME,
|
|
4701
3353
|
liveConfigGateway,
|
|
4702
3354
|
findConfigFile,
|
|
@@ -4705,12 +3357,5 @@ export {
|
|
|
4705
3357
|
fileSettings,
|
|
4706
3358
|
settleRunResources,
|
|
4707
3359
|
invalidConfig,
|
|
4708
|
-
configResolver
|
|
4709
|
-
rejectedCredentialShape,
|
|
4710
|
-
rejectedCredentialFacts,
|
|
4711
|
-
rejectedCredentialText,
|
|
4712
|
-
credentialOriginRows,
|
|
4713
|
-
prBuildRefusalFacts,
|
|
4714
|
-
prBuildRefusalErrors,
|
|
4715
|
-
testserverPoolDefinition
|
|
3360
|
+
configResolver
|
|
4716
3361
|
};
|