@cnc-tools/storm 0.7.0 → 0.8.1
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/build-info.js +1 -1
- package/dist/commands/exec/cleanup.d.ts +3 -3
- package/dist/commands/exec/cleanup.js +1 -1
- package/dist/commands/exec/command.d.ts +771 -1
- package/dist/commands/exec/command.js +1 -1
- package/dist/commands/exec/live-view.js +3 -2
- package/dist/commands/exec/metadata.d.ts +1 -1
- package/dist/commands/exec/metadata.js +4 -0
- package/dist/commands/exec/mint-failed.d.ts +28 -0
- package/dist/commands/exec/outcomes.d.ts +476 -0
- package/dist/commands/exec/progress.js +3 -5
- package/dist/commands/exec/run-command.d.ts +2 -2
- package/dist/commands/exec/run-metadata.d.ts +1 -1
- package/dist/commands/exec/run-metadata.js +1 -1
- package/dist/commands/exec/tests-summary.d.ts +1 -1
- package/dist/commands/exec/tests-summary.js +1 -1
- package/dist/commands/runs/facts.d.ts +2 -2
- package/dist/commands/runs/facts.js +1 -1
- package/dist/commands/runs/list/command.d.ts +129 -1
- package/dist/commands/runs/list/command.js +1 -1
- package/dist/commands/runs/list/outcomes.d.ts +16 -0
- package/dist/commands/runs/list/outcomes.js +1 -1
- package/dist/commands/runs/logs/command.d.ts +263 -1
- package/dist/commands/runs/logs/command.js +1 -1
- package/dist/commands/runs/logs/outcomes.d.ts +105 -0
- package/dist/commands/runs/logs/outcomes.js +1 -1
- package/dist/commands/runs/show/command.d.ts +329 -1
- package/dist/commands/runs/show/command.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +71 -0
- package/dist/commands/runs/show/outcomes.js +3 -3
- package/dist/commands/vitest/command.d.ts +886 -1
- package/dist/commands/vitest/command.js +1 -1
- package/dist/commands/vitest/metadata.d.ts +1 -1
- package/dist/commands/vitest/metadata.js +4 -0
- package/dist/commands/vitest/outcomes.d.ts +295 -0
- package/dist/config/errors.d.ts +73 -0
- package/dist/config/schema.d.ts +1 -1
- package/dist/config-file/define.d.ts +4 -3
- package/dist/config-file/define.js +1 -1
- package/dist/config-file/toolchain.js +1 -1
- package/dist/core/command-slots.d.ts +8 -2
- package/dist/core/command-slots.js +6 -2
- package/dist/core/index.d.ts +1 -1
- package/dist/credential/index.d.ts +1 -0
- package/dist/credential/index.js +1 -0
- package/dist/credential/settle.d.ts +20 -0
- package/dist/credential/target.d.ts +6 -0
- package/dist/credential/target.js +7 -0
- package/dist/resources/github/command.d.ts +54 -2
- package/dist/resources/github/config.js +1 -1
- package/dist/resources/github/index.js +1 -1
- package/dist/resources/github/resource.js +2 -2
- package/dist/resources/testserver/command.d.ts +208 -10
- package/dist/resources/testserver/command.js +7 -0
- package/dist/resources/testserver/commands/create/command.d.ts +810 -1
- package/dist/resources/testserver/commands/create/command.js +73 -23
- package/dist/resources/testserver/commands/create/metadata.js +6 -2
- package/dist/resources/testserver/commands/create/outcomes.d.ts +347 -0
- package/dist/resources/testserver/commands/create/outcomes.js +14 -1
- package/dist/resources/testserver/commands/list/command.d.ts +84 -1
- package/dist/resources/testserver/commands/list/command.js +1 -1
- package/dist/resources/testserver/commands/list/outcomes.d.ts +16 -0
- package/dist/resources/testserver/config.js +14 -4
- package/dist/resources/testserver/events.d.ts +11 -0
- package/dist/resources/testserver/index.js +8 -7
- package/dist/resources/testserver/lane.js +1 -0
- package/dist/resources/testserver/live/gateways.d.ts +2 -0
- package/dist/resources/testserver/live/gateways.js +16 -3
- package/dist/resources/testserver/pool/channels.d.ts +5 -2
- package/dist/resources/testserver/pool/channels.js +1 -1
- package/dist/resources/testserver/pool/create.d.ts +9 -2
- package/dist/resources/testserver/pool/create.js +8 -5
- package/dist/resources/testserver/pool/gateways.d.ts +6 -0
- package/dist/resources/testserver/pool/index.d.ts +1 -0
- package/dist/resources/testserver/pool/index.js +1 -0
- package/dist/resources/testserver/pool/live/pool-records.js +6 -2
- package/dist/resources/testserver/pool/pull-request.d.ts +96 -0
- package/dist/resources/testserver/pool/pull-request.js +118 -0
- package/dist/resources/testserver/pr-build-facts.d.ts +130 -0
- package/dist/resources/testserver/pr-build-facts.js +261 -0
- package/dist/resources/testserver/presentation.d.ts +2 -2
- package/dist/resources/testserver/presentation.js +13 -3
- package/dist/resources/testserver/provider.d.ts +16 -6
- package/dist/resources/testserver/provider.js +55 -16
- package/dist/resources/testserver/pull-request/gateways.d.ts +117 -0
- package/dist/resources/testserver/pull-request/gateways.js +5 -0
- package/dist/resources/testserver/pull-request/index.d.ts +5 -0
- package/dist/resources/testserver/pull-request/index.js +6 -0
- package/dist/resources/testserver/pull-request/live/github-rest.d.ts +28 -0
- package/dist/resources/testserver/pull-request/live/github-rest.js +114 -0
- package/dist/resources/testserver/pull-request/live/github-token-gateway.d.ts +12 -0
- package/dist/resources/testserver/pull-request/live/github-token-gateway.js +39 -0
- package/dist/resources/testserver/pull-request/live/pull-request-gateway.d.ts +10 -0
- package/dist/resources/testserver/pull-request/live/pull-request-gateway.js +27 -0
- package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.d.ts +21 -0
- package/dist/resources/testserver/pull-request/live/testserver-workflow-gateway.js +64 -0
- package/dist/resources/testserver/ran.d.ts +5 -0
- package/dist/resources/testserver/ran.js +19 -3
- package/dist/resources/testserver/resource.d.ts +5 -1
- package/dist/resources/testserver/resource.js +2 -2
- package/dist/resources/testserver/sandbox/build-reference.d.ts +38 -0
- package/dist/resources/testserver/sandbox/build-reference.js +79 -0
- package/dist/resources/testserver/sandbox/index.d.ts +1 -0
- package/dist/resources/testserver/sandbox/index.js +1 -0
- package/dist/resources.d.ts +265 -15
- package/dist/sdk/index.js +2 -2
- package/dist/story/command-line.d.ts +34 -0
- package/dist/story/command-line.js +100 -0
- package/dist/story/index.d.ts +1 -0
- package/dist/story/index.js +3 -2
- package/dist/vercel-cli/context.js +1 -1
- package/dist/vercel-cli/index.js +1 -1
- package/dist/vitest/config.js +2 -2
- package/dist/vitest/fixtures.d.ts +1 -1
- package/dist/vitest/fixtures.js +1 -1
- package/dist/vitest/index.js +3 -3
- package/dist/vitest/plan.js +1 -1
- package/package.json +2 -3
- package/skills/overview.md +2 -0
- package/skills/testserver-builds.md +82 -0
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
// lease once the command has stopped. Its lane is `testserver`, and its facts feed the `ran` and `canceled` outcomes.
|
|
4
4
|
// It is written against its own kind only.
|
|
5
5
|
import { runLimited, } from "../../core/index.js";
|
|
6
|
-
import { buildMatch, createPooledSandbox, leaseUsable, minutesSince, releaseLeases, resolveBuild, } from "./pool/index.js";
|
|
6
|
+
import { buildMatch, createPooledSandbox, leaseUsable, minutesSince, releaseLeases, resolveBuild, resolvePrBuild, } from "./pool/index.js";
|
|
7
|
+
import { parseBuildReference, } from "./sandbox/index.js";
|
|
7
8
|
import { CREATE_CONCURRENCY } from "./options.js";
|
|
8
9
|
/**
|
|
9
10
|
* The run provider of the Testserver pool resource.
|
|
10
11
|
*
|
|
11
12
|
* - Preparing it prepares the pool's files; a pool that can't be prepared ends the run `pool-unavailable`.
|
|
12
|
-
* - Acquiring it provisions (`provision`): it resolves the build
|
|
13
|
+
* - Acquiring it provisions (`provision`): it resolves the build (a PR build reference from GitHub on the host, its
|
|
14
|
+
* GitHub token going nowhere else), leases, and creates the rest with the run's
|
|
13
15
|
* credential source: in a local run the one its credential choice names, in a runner run the run's one mint. Each
|
|
14
16
|
* host leased goes onto `owned` as it is leased. A mint that fails with no Testserver sandbox in hand ends the run
|
|
15
17
|
* as the run's own `mint-failed`.
|
|
@@ -104,16 +106,26 @@ async function provision(context, request, create, signal, progress, held) {
|
|
|
104
106
|
});
|
|
105
107
|
if (signal.aborted)
|
|
106
108
|
return canceled();
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
109
|
+
const reference = parseBuildReference(request.build);
|
|
110
|
+
let resolution;
|
|
111
|
+
if (reference.ok && reference.reference.kind === "pull-request") {
|
|
112
|
+
const resolved = await resolvePullRequestBuild(context, reference.reference.number, progress);
|
|
113
|
+
if (resolved.kind !== "resolved")
|
|
114
|
+
return resolved;
|
|
115
|
+
resolution = resolved.resolution;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
resolution = await resolveBuild(context, { build: request.build, credential: create?.source });
|
|
119
|
+
if (resolution.kind === "as-written")
|
|
120
|
+
await progress.emit({ kind: "build-unresolved", channel: resolution.channel, reason: resolution.reason });
|
|
121
|
+
if (resolution.kind === "old-channel-resolution")
|
|
122
|
+
await progress.emit({
|
|
123
|
+
kind: "old-channel-resolution",
|
|
124
|
+
channel: resolution.channel,
|
|
125
|
+
build: resolution.build,
|
|
126
|
+
ageMinutes: minutesSince(resolution.learnedAt, context.clock.now()),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
117
129
|
if (signal.aborted)
|
|
118
130
|
return canceled();
|
|
119
131
|
const match = buildMatch(resolution);
|
|
@@ -144,7 +156,12 @@ async function provision(context, request, create, signal, progress, held) {
|
|
|
144
156
|
else if (missing > 0 && create !== undefined) {
|
|
145
157
|
if (signal.aborted)
|
|
146
158
|
return canceled();
|
|
147
|
-
const { rejected, credentialFailure, uncreatedCount, ...made } = await createMissing(context, {
|
|
159
|
+
const { rejected, credentialFailure, uncreatedCount, ...made } = await createMissing(context, {
|
|
160
|
+
source: create.source,
|
|
161
|
+
target: createTarget(request.build, resolution),
|
|
162
|
+
ttlMinutes: create.ttlMinutes,
|
|
163
|
+
count: missing,
|
|
164
|
+
}, signal, progress, held);
|
|
148
165
|
tally = made;
|
|
149
166
|
if (rejected !== undefined)
|
|
150
167
|
return {
|
|
@@ -183,6 +200,28 @@ async function provision(context, request, create, signal, progress, held) {
|
|
|
183
200
|
notCreated,
|
|
184
201
|
};
|
|
185
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Resolves the PR build reference `pr:<pr>` from GitHub (`resolvePrBuild`), and says what it resolved to. One it
|
|
205
|
+
* couldn't resolve ends the run with a refusal of its own. It needs no credential, so it works under `noCreate` too.
|
|
206
|
+
*/
|
|
207
|
+
async function resolvePullRequestBuild(context, pr, progress) {
|
|
208
|
+
const outcome = await resolvePrBuild(context, { pr });
|
|
209
|
+
if (!outcome.ok)
|
|
210
|
+
return outcome.refusal;
|
|
211
|
+
const { resolution } = outcome;
|
|
212
|
+
const { headSha, build, merged, from } = resolution;
|
|
213
|
+
await progress.emit({ kind: "pr-build-resolved", pr, headSha, build, merged, from });
|
|
214
|
+
return { kind: "resolved", resolution };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* What the run's creates go to: for a PR build reference, the PR build it resolved to, with the head commit it was made
|
|
218
|
+
* from, so a later run finds it in the pool; otherwise the build setting as written, which the control plane resolves.
|
|
219
|
+
*/
|
|
220
|
+
function createTarget(requestedBuild, resolution) {
|
|
221
|
+
return resolution.kind === "pull-request"
|
|
222
|
+
? { build: resolution.build, requestedBuild, headSha: resolution.headSha }
|
|
223
|
+
: { build: requestedBuild, requestedBuild };
|
|
224
|
+
}
|
|
186
225
|
/**
|
|
187
226
|
* Creates `count` Testserver sandboxes, 8 at a time, each leased as it exists. It asks `source` for a credential
|
|
188
227
|
* once before it reports the creates, so a source that can't give one stops it before any create, with every create
|
|
@@ -196,7 +235,7 @@ async function provision(context, request, create, signal, progress, held) {
|
|
|
196
235
|
* first failure, if any, and `uncreatedCount` how many creates never ran.
|
|
197
236
|
*/
|
|
198
237
|
async function createMissing(context, request, signal, progress, held) {
|
|
199
|
-
const { source,
|
|
238
|
+
const { source, target, ttlMinutes, count } = request;
|
|
200
239
|
const first = await source.get();
|
|
201
240
|
if (!first.ok)
|
|
202
241
|
return {
|
|
@@ -207,7 +246,7 @@ async function createMissing(context, request, signal, progress, held) {
|
|
|
207
246
|
credentialFailure: first.failure,
|
|
208
247
|
uncreatedCount: count,
|
|
209
248
|
};
|
|
210
|
-
await progress.emit({ kind: "creating", count, build });
|
|
249
|
+
await progress.emit({ kind: "creating", count, build: target.build });
|
|
211
250
|
let rejected;
|
|
212
251
|
let credentialFailure;
|
|
213
252
|
const mayCreate = () => rejected === undefined && credentialFailure === undefined && !signal.aborted;
|
|
@@ -222,7 +261,7 @@ async function createMissing(context, request, signal, progress, held) {
|
|
|
222
261
|
return undefined;
|
|
223
262
|
const { credential } = got;
|
|
224
263
|
await progress.emit({ kind: "create-started", index, count });
|
|
225
|
-
const outcome = await createPooledSandbox(context, { credential,
|
|
264
|
+
const outcome = await createPooledSandbox(context, { credential, ...target, ttlMinutes, lease: true }, { onProgress: (message) => progress.emit({ kind: "create-progress", index, count, message }) });
|
|
226
265
|
if (outcome.kind === "pooled")
|
|
227
266
|
held.push(outcome.host);
|
|
228
267
|
if (outcome.kind === "create-failed" && outcome.failure.kind === "rejected")
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** What GitHub says of one pull request: its head commit and branch, whether it is open, and whether it merged. */
|
|
2
|
+
export interface PullRequestHead {
|
|
3
|
+
/** The head commit, 40 lowercase hex characters. */
|
|
4
|
+
readonly headSha: string;
|
|
5
|
+
/** The pull request's branch, such as `schrockn/testserver-registrar-docs`. */
|
|
6
|
+
readonly headRef: string;
|
|
7
|
+
readonly state: "open" | "closed";
|
|
8
|
+
readonly merged: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Why a GitHub REST call failed. No message holds the token.
|
|
12
|
+
*
|
|
13
|
+
* - `not-found`: GitHub answered 404: there is no such pull request or run, or the token can't read the repository.
|
|
14
|
+
* - `rejected`: GitHub answered 401 or 403; `message` is what GitHub said.
|
|
15
|
+
* - `http-error`: any other status that isn't 2xx; `message` is what GitHub said, or the status.
|
|
16
|
+
* - `connect-failed`: no answer came: `code` is the network error's code, such as `ENOTFOUND`, or its message.
|
|
17
|
+
* - `timeout`: no answer within `seconds`.
|
|
18
|
+
* - `malformed`: the answer wasn't what was asked for.
|
|
19
|
+
*/
|
|
20
|
+
export type GitHubFailure = {
|
|
21
|
+
readonly kind: "not-found";
|
|
22
|
+
readonly status: 404;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "rejected";
|
|
25
|
+
readonly status: 401 | 403;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "http-error";
|
|
29
|
+
readonly status: number;
|
|
30
|
+
readonly message: string;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "connect-failed";
|
|
33
|
+
readonly code: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "timeout";
|
|
36
|
+
readonly seconds: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: "malformed";
|
|
39
|
+
readonly detail: string;
|
|
40
|
+
};
|
|
41
|
+
export type PullRequestHeadOutcome = {
|
|
42
|
+
readonly ok: true;
|
|
43
|
+
readonly head: PullRequestHead;
|
|
44
|
+
} | {
|
|
45
|
+
readonly ok: false;
|
|
46
|
+
readonly failure: GitHubFailure;
|
|
47
|
+
};
|
|
48
|
+
/** GitHub's pull requests, read with a GitHub token. No method rejects. */
|
|
49
|
+
export interface PullRequestGateway {
|
|
50
|
+
/** `GET repos/{repo}/pulls/{number}`: pull request `number`'s head commit, branch and state. */
|
|
51
|
+
head(request: {
|
|
52
|
+
readonly repo: string;
|
|
53
|
+
readonly number: number;
|
|
54
|
+
readonly token: string;
|
|
55
|
+
}): Promise<PullRequestHeadOutcome>;
|
|
56
|
+
}
|
|
57
|
+
/** One run of vercel/api's `Testserver` workflow for a pull request push. */
|
|
58
|
+
export interface TestserverRun {
|
|
59
|
+
/** The run's id on GitHub Actions. */
|
|
60
|
+
readonly id: number;
|
|
61
|
+
/** The pull request head commit the run was for, 40 lowercase hex characters. */
|
|
62
|
+
readonly headSha: string;
|
|
63
|
+
/** When the run started, as GitHub writes it. */
|
|
64
|
+
readonly createdAt: string;
|
|
65
|
+
}
|
|
66
|
+
/** The PR build a run's `Bundle & Publish` job published: its pull request number (`builds/pr-<pr>/`) and name. */
|
|
67
|
+
export interface PublishedBuild {
|
|
68
|
+
readonly pr: number;
|
|
69
|
+
readonly name: string;
|
|
70
|
+
}
|
|
71
|
+
export type TestserverRunsOutcome = {
|
|
72
|
+
readonly ok: true;
|
|
73
|
+
readonly runs: readonly TestserverRun[];
|
|
74
|
+
} | {
|
|
75
|
+
readonly ok: false;
|
|
76
|
+
readonly failure: GitHubFailure;
|
|
77
|
+
};
|
|
78
|
+
export type PublishedBuildOutcome = {
|
|
79
|
+
readonly ok: true;
|
|
80
|
+
readonly build: PublishedBuild | undefined;
|
|
81
|
+
} | {
|
|
82
|
+
readonly ok: false;
|
|
83
|
+
readonly failure: GitHubFailure;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* vercel/api's `Testserver` workflow on GitHub Actions, read with a GitHub token: its runs for pushes to a pull request,
|
|
87
|
+
* and the PR build each one published. No method rejects.
|
|
88
|
+
*/
|
|
89
|
+
export interface TestserverWorkflowGateway {
|
|
90
|
+
/** The workflow's newest `pull_request` runs on branch `branch` of `repo`, newest first. */
|
|
91
|
+
runs(request: {
|
|
92
|
+
readonly repo: string;
|
|
93
|
+
readonly branch: string;
|
|
94
|
+
readonly token: string;
|
|
95
|
+
}): Promise<TestserverRunsOutcome>;
|
|
96
|
+
/**
|
|
97
|
+
* The PR build run `runId`'s `Bundle & Publish` job published; undefined when the job hasn't succeeded, or its log
|
|
98
|
+
* names no PR build.
|
|
99
|
+
*/
|
|
100
|
+
publishedBuild(request: {
|
|
101
|
+
readonly repo: string;
|
|
102
|
+
readonly runId: number;
|
|
103
|
+
readonly token: string;
|
|
104
|
+
}): Promise<PublishedBuildOutcome>;
|
|
105
|
+
}
|
|
106
|
+
/** Where a GitHub token came from. */
|
|
107
|
+
export type GitHubTokenOrigin = "GITHUB_TOKEN" | "GH_TOKEN" | "gh auth token";
|
|
108
|
+
/** A GitHub token, and where it came from. */
|
|
109
|
+
export interface GitHubToken {
|
|
110
|
+
readonly token: string;
|
|
111
|
+
readonly origin: GitHubTokenOrigin;
|
|
112
|
+
}
|
|
113
|
+
/** Finds a GitHub token on the host. It never rejects. */
|
|
114
|
+
export interface GitHubTokenGateway {
|
|
115
|
+
/** The first of `GITHUB_TOKEN`, `GH_TOKEN`, then `gh auth token`'s output; undefined when none gives one. */
|
|
116
|
+
token(): Promise<GitHubToken | undefined>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// What the Testserver pool resource asks GitHub on the host about a vercel/api pull request: its head commit, the runs of
|
|
2
|
+
// vercel/api's `Testserver` workflow on it and the PR build each run published, and a GitHub token to ask with. The
|
|
3
|
+
// token never leaves the host: storm uses it only for these requests, and no run payload, runner sandbox, command
|
|
4
|
+
// environment, progress line, outcome or run directory holds it.
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { GitHubFailure, GitHubToken, GitHubTokenGateway, GitHubTokenOrigin, PublishedBuild, PublishedBuildOutcome, PullRequestGateway, PullRequestHead, PullRequestHeadOutcome, TestserverRun, TestserverRunsOutcome, TestserverWorkflowGateway, } from "./gateways.ts";
|
|
2
|
+
export { type GitHubRestOptions } from "./live/github-rest.ts";
|
|
3
|
+
export { GH_TOKEN_TIMEOUT_MS, liveGitHubTokenGateway } from "./live/github-token-gateway.ts";
|
|
4
|
+
export { livePullRequestGateway } from "./live/pull-request-gateway.ts";
|
|
5
|
+
export { BUNDLE_JOB, liveTestserverWorkflowGateway, type LiveTestserverWorkflowOptions, TESTSERVER_WORKFLOW, } from "./live/testserver-workflow-gateway.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The Testserver folder's `pull-request/` barrel, for the other files in `resources/testserver/`. Code outside that
|
|
2
|
+
// folder imports `resources/testserver/index.ts` instead.
|
|
3
|
+
export {} from "./live/github-rest.js";
|
|
4
|
+
export { GH_TOKEN_TIMEOUT_MS, liveGitHubTokenGateway } from "./live/github-token-gateway.js";
|
|
5
|
+
export { livePullRequestGateway } from "./live/pull-request-gateway.js";
|
|
6
|
+
export { BUNDLE_JOB, liveTestserverWorkflowGateway, TESTSERVER_WORKFLOW, } from "./live/testserver-workflow-gateway.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { GitHubFailure } from "../gateways.ts";
|
|
3
|
+
export interface GitHubRestOptions {
|
|
4
|
+
/** GitHub's REST API origin, `https://api.github.com`, with no trailing slash. */
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
/** How long one call, its body included, may take. */
|
|
7
|
+
readonly timeoutMs: number;
|
|
8
|
+
}
|
|
9
|
+
/** A GitHub REST answer: a 2xx's body, or the failure. */
|
|
10
|
+
export type GitHubAnswer<T> = {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
readonly value: T;
|
|
13
|
+
} | {
|
|
14
|
+
readonly ok: false;
|
|
15
|
+
readonly failure: GitHubFailure;
|
|
16
|
+
};
|
|
17
|
+
/** `text` with `token` replaced by `<token>`. */
|
|
18
|
+
export declare function hideToken(text: string, token: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* `GET {origin}/{path}` with the token as a bearer token, no redirect followed and a timeout for the whole call: a 2xx
|
|
21
|
+
* answer's body parsed by `schema`, or the failure, with the token replaced by `<token>` in every message.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getJson<T>(options: GitHubRestOptions, token: string, path: string, schema: z.ZodType<T>): Promise<GitHubAnswer<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* `GET {origin}/{path}`, an endpoint that answers with a redirect to the text it names, such as a job's log: the text,
|
|
26
|
+
* fetched from the redirect's location with no token, since that URL is signed. A 2xx answer's own body is the text.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getRedirectedText(options: GitHubRestOptions, token: string, path: string): Promise<GitHubAnswer<string>>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const errorSchema = z.object({ message: z.string() });
|
|
3
|
+
/** GitHub's REST headers for a call with `token`. */
|
|
4
|
+
function headers(token) {
|
|
5
|
+
return {
|
|
6
|
+
accept: "application/vnd.github+json",
|
|
7
|
+
authorization: `Bearer ${token}`,
|
|
8
|
+
"x-github-api-version": "2022-11-28",
|
|
9
|
+
"user-agent": "storm",
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** `text` with `token` replaced by `<token>`. */
|
|
13
|
+
export function hideToken(text, token) {
|
|
14
|
+
return token === "" ? text : text.replaceAll(token, "<token>");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `GET {origin}/{path}` with the token as a bearer token, no redirect followed and a timeout for the whole call: a 2xx
|
|
18
|
+
* answer's body parsed by `schema`, or the failure, with the token replaced by `<token>` in every message.
|
|
19
|
+
*/
|
|
20
|
+
export async function getJson(options, token, path, schema) {
|
|
21
|
+
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
22
|
+
try {
|
|
23
|
+
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
24
|
+
const text = await response.text();
|
|
25
|
+
if (response.status < 200 || response.status >= 300)
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
failure: statusFailure(response.status, hideToken(githubMessage(text, response.status), token)),
|
|
29
|
+
};
|
|
30
|
+
let json;
|
|
31
|
+
try {
|
|
32
|
+
json = JSON.parse(text);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { ok: false, failure: { kind: "malformed", detail: "the answer isn't JSON" } };
|
|
36
|
+
}
|
|
37
|
+
const parsed = schema.safeParse(json);
|
|
38
|
+
if (!parsed.success) {
|
|
39
|
+
const issue = parsed.error.issues[0];
|
|
40
|
+
const where = issue === undefined || issue.path.length === 0 ? "the answer" : issue.path.join(".");
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
failure: { kind: "malformed", detail: hideToken(`${where}: ${issue?.message ?? "unexpected"}`, token) },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { ok: true, value: parsed.data };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `GET {origin}/{path}`, an endpoint that answers with a redirect to the text it names, such as a job's log: the text,
|
|
54
|
+
* fetched from the redirect's location with no token, since that URL is signed. A 2xx answer's own body is the text.
|
|
55
|
+
*/
|
|
56
|
+
export async function getRedirectedText(options, token, path) {
|
|
57
|
+
const signal = AbortSignal.timeout(options.timeoutMs);
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(`${options.origin}/${path}`, { headers: headers(token), redirect: "manual", signal });
|
|
60
|
+
if (response.status >= 200 && response.status < 300)
|
|
61
|
+
return { ok: true, value: await response.text() };
|
|
62
|
+
const location = response.headers.get("location");
|
|
63
|
+
if (response.status < 300 || response.status >= 400 || location === null) {
|
|
64
|
+
const text = await response.text();
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
failure: statusFailure(response.status, hideToken(githubMessage(text, response.status), token)),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
await response.body?.cancel().catch(() => { });
|
|
71
|
+
const redirected = await fetch(location, { redirect: "follow", signal });
|
|
72
|
+
const text = await redirected.text();
|
|
73
|
+
if (!redirected.ok)
|
|
74
|
+
return { ok: false, failure: statusFailure(redirected.status, `HTTP ${redirected.status}`) };
|
|
75
|
+
return { ok: true, value: text };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return { ok: false, failure: thrownFailure(error, signal, options, token) };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** The failure a status that isn't 2xx means. */
|
|
82
|
+
function statusFailure(status, message) {
|
|
83
|
+
if (status === 404)
|
|
84
|
+
return { kind: "not-found", status };
|
|
85
|
+
if (status === 401 || status === 403)
|
|
86
|
+
return { kind: "rejected", status, message };
|
|
87
|
+
return { kind: "http-error", status, message };
|
|
88
|
+
}
|
|
89
|
+
/** What GitHub said in an error answer: its `message`, or the status when the body has none. */
|
|
90
|
+
function githubMessage(text, status) {
|
|
91
|
+
try {
|
|
92
|
+
const parsed = errorSchema.safeParse(JSON.parse(text));
|
|
93
|
+
if (parsed.success)
|
|
94
|
+
return parsed.data.message;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Not JSON: the status says enough.
|
|
98
|
+
}
|
|
99
|
+
return `HTTP ${status}`;
|
|
100
|
+
}
|
|
101
|
+
/** What a rejected `fetch` means: `timeout` when its signal aborted it, else `connect-failed` with its code. */
|
|
102
|
+
function thrownFailure(error, signal, options, token) {
|
|
103
|
+
if (signal.aborted)
|
|
104
|
+
return { kind: "timeout", seconds: options.timeoutMs / 1000 };
|
|
105
|
+
return { kind: "connect-failed", code: hideToken(errorCode(error), token) };
|
|
106
|
+
}
|
|
107
|
+
/** A rejected `fetch`'s network error code, such as `ENOTFOUND`, or its message when it has none. */
|
|
108
|
+
function errorCode(error) {
|
|
109
|
+
if (!(error instanceof Error))
|
|
110
|
+
return String(error);
|
|
111
|
+
const cause = error.cause;
|
|
112
|
+
const code = typeof cause === "object" && cause !== null ? cause.code : undefined;
|
|
113
|
+
return typeof code === "string" ? code : error.message;
|
|
114
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GitHubTokenGateway } from "../gateways.ts";
|
|
2
|
+
/** How long `gh auth token` may run before it is killed. */
|
|
3
|
+
export declare const GH_TOKEN_TIMEOUT_MS = 5000;
|
|
4
|
+
/**
|
|
5
|
+
* Finds a GitHub token on the host: `GITHUB_TOKEN` in `env`, then `GH_TOKEN`, each only when it isn't blank, then
|
|
6
|
+
* the output of `gh auth token --hostname github.com`, run with no shell, `env` as its environment and a 5-second
|
|
7
|
+
* timeout, when it exits 0 with output. A missing `gh`, a timeout or another exit gives no token. It never rejects,
|
|
8
|
+
* and it logs nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function liveGitHubTokenGateway(options: {
|
|
11
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
}): GitHubTokenGateway;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
/** How long `gh auth token` may run before it is killed. */
|
|
3
|
+
export const GH_TOKEN_TIMEOUT_MS = 5_000;
|
|
4
|
+
/**
|
|
5
|
+
* Finds a GitHub token on the host: `GITHUB_TOKEN` in `env`, then `GH_TOKEN`, each only when it isn't blank, then
|
|
6
|
+
* the output of `gh auth token --hostname github.com`, run with no shell, `env` as its environment and a 5-second
|
|
7
|
+
* timeout, when it exits 0 with output. A missing `gh`, a timeout or another exit gives no token. It never rejects,
|
|
8
|
+
* and it logs nothing.
|
|
9
|
+
*/
|
|
10
|
+
export function liveGitHubTokenGateway(options) {
|
|
11
|
+
return {
|
|
12
|
+
token: async () => {
|
|
13
|
+
for (const origin of ["GITHUB_TOKEN", "GH_TOKEN"]) {
|
|
14
|
+
const token = options.env[origin]?.trim();
|
|
15
|
+
if (token !== undefined && token !== "")
|
|
16
|
+
return { token, origin };
|
|
17
|
+
}
|
|
18
|
+
const token = await ghAuthToken(options.env);
|
|
19
|
+
return token === undefined ? undefined : { token, origin: "gh auth token" };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `gh auth token`'s output, trimmed, or undefined when it fails or prints nothing. It uses `execFile`'s callback
|
|
25
|
+
* form, as `vercel` runs do.
|
|
26
|
+
*/
|
|
27
|
+
function ghAuthToken(env) {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
try {
|
|
30
|
+
execFile("gh", ["auth", "token", "--hostname", "github.com"], { env: { ...env }, timeout: GH_TOKEN_TIMEOUT_MS, encoding: "utf8" }, (error, stdout) => {
|
|
31
|
+
const token = typeof stdout === "string" ? stdout.trim() : "";
|
|
32
|
+
resolve(error === null && token !== "" ? token : undefined);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
resolve(undefined);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PullRequestGateway } from "../gateways.ts";
|
|
2
|
+
import { type GitHubRestOptions } from "./github-rest.ts";
|
|
3
|
+
/**
|
|
4
|
+
* GitHub's REST API over `fetch`: `GET repos/{repo}/pulls/{number}` with the token as a bearer token, no redirect
|
|
5
|
+
* followed and a timeout for the whole call. A failure says what GitHub said (its `message`) or what the connection
|
|
6
|
+
* did, with the token replaced by `<token>`. It never rejects.
|
|
7
|
+
*/
|
|
8
|
+
export declare function livePullRequestGateway(options: GitHubRestOptions): PullRequestGateway;
|
|
9
|
+
/** `owner/name` with each part encoded. */
|
|
10
|
+
export declare function repoPath(repo: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getJson } from "./github-rest.js";
|
|
3
|
+
const pullSchema = z.object({
|
|
4
|
+
head: z.object({ sha: z.string().regex(/^[0-9a-f]{40}$/), ref: z.string().min(1) }),
|
|
5
|
+
state: z.enum(["open", "closed"]),
|
|
6
|
+
merged: z.boolean(),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* GitHub's REST API over `fetch`: `GET repos/{repo}/pulls/{number}` with the token as a bearer token, no redirect
|
|
10
|
+
* followed and a timeout for the whole call. A failure says what GitHub said (its `message`) or what the connection
|
|
11
|
+
* did, with the token replaced by `<token>`. It never rejects.
|
|
12
|
+
*/
|
|
13
|
+
export function livePullRequestGateway(options) {
|
|
14
|
+
return {
|
|
15
|
+
head: async ({ repo, number, token }) => {
|
|
16
|
+
const answered = await getJson(options, token, `repos/${repoPath(repo)}/pulls/${number}`, pullSchema);
|
|
17
|
+
if (!answered.ok)
|
|
18
|
+
return answered;
|
|
19
|
+
const { head, state, merged } = answered.value;
|
|
20
|
+
return { ok: true, head: { headSha: head.sha, headRef: head.ref, state, merged } };
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** `owner/name` with each part encoded. */
|
|
25
|
+
export function repoPath(repo) {
|
|
26
|
+
return repo.split("/").map(encodeURIComponent).join("/");
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TestserverWorkflowGateway } from "../gateways.ts";
|
|
2
|
+
import { type GitHubRestOptions } from "./github-rest.ts";
|
|
3
|
+
/** vercel/api's `Testserver` workflow file, whose `Bundle & Publish` job publishes a PR build for each push. */
|
|
4
|
+
export declare const TESTSERVER_WORKFLOW = "testserver-bundle-publish.yml";
|
|
5
|
+
/** The job of the `Testserver` workflow that bundles Testserver and publishes the build. */
|
|
6
|
+
export declare const BUNDLE_JOB = "Bundle & Publish";
|
|
7
|
+
export interface LiveTestserverWorkflowOptions extends GitHubRestOptions {
|
|
8
|
+
/** How long one job log's download may take. */
|
|
9
|
+
readonly logTimeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* vercel/api's `Testserver` workflow on GitHub's REST API over `fetch`, with the token as a bearer token:
|
|
13
|
+
*
|
|
14
|
+
* - `runs`: `GET repos/{repo}/actions/workflows/testserver-bundle-publish.yml/runs?event=pull_request&branch=…`.
|
|
15
|
+
* - `publishedBuild`: `GET repos/{repo}/actions/runs/{id}/jobs` for its latest attempt's `Bundle & Publish` job, and,
|
|
16
|
+
* when that job succeeded, `GET repos/{repo}/actions/jobs/{id}/logs`, whose redirect it follows with no token, for
|
|
17
|
+
* the line that names the build.
|
|
18
|
+
*
|
|
19
|
+
* A failure says what GitHub said or what the connection did, with the token replaced by `<token>`. It never rejects.
|
|
20
|
+
*/
|
|
21
|
+
export declare function liveTestserverWorkflowGateway(options: LiveTestserverWorkflowOptions): TestserverWorkflowGateway;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getJson, getRedirectedText } from "./github-rest.js";
|
|
3
|
+
import { repoPath } from "./pull-request-gateway.js";
|
|
4
|
+
/** vercel/api's `Testserver` workflow file, whose `Bundle & Publish` job publishes a PR build for each push. */
|
|
5
|
+
export const TESTSERVER_WORKFLOW = "testserver-bundle-publish.yml";
|
|
6
|
+
/** The job of the `Testserver` workflow that bundles Testserver and publishes the build. */
|
|
7
|
+
export const BUNDLE_JOB = "Bundle & Publish";
|
|
8
|
+
/** How many of a branch's newest runs `runs` lists. */
|
|
9
|
+
const RUNS_LISTED = 30;
|
|
10
|
+
/**
|
|
11
|
+
* The line the `Bundle & Publish` job's log names its build with: `📦 Bundle will be: builds/pr-104196/<name>`. The
|
|
12
|
+
* job also echoes the command that prints it, whose `${FOLDER}/${NAME}` doesn't match.
|
|
13
|
+
*/
|
|
14
|
+
const BUNDLE_LINE = /📦 Bundle will be: builds\/pr-([1-9][0-9]*)\/([^\s/]+)/;
|
|
15
|
+
const runsSchema = z.object({
|
|
16
|
+
workflow_runs: z.array(z.object({
|
|
17
|
+
id: z.number(),
|
|
18
|
+
head_sha: z.string().regex(/^[0-9a-f]{40}$/),
|
|
19
|
+
created_at: z.string().min(1),
|
|
20
|
+
})),
|
|
21
|
+
});
|
|
22
|
+
const jobsSchema = z.object({
|
|
23
|
+
jobs: z.array(z.object({ id: z.number(), name: z.string(), conclusion: z.string().nullable() })),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* vercel/api's `Testserver` workflow on GitHub's REST API over `fetch`, with the token as a bearer token:
|
|
27
|
+
*
|
|
28
|
+
* - `runs`: `GET repos/{repo}/actions/workflows/testserver-bundle-publish.yml/runs?event=pull_request&branch=…`.
|
|
29
|
+
* - `publishedBuild`: `GET repos/{repo}/actions/runs/{id}/jobs` for its latest attempt's `Bundle & Publish` job, and,
|
|
30
|
+
* when that job succeeded, `GET repos/{repo}/actions/jobs/{id}/logs`, whose redirect it follows with no token, for
|
|
31
|
+
* the line that names the build.
|
|
32
|
+
*
|
|
33
|
+
* A failure says what GitHub said or what the connection did, with the token replaced by `<token>`. It never rejects.
|
|
34
|
+
*/
|
|
35
|
+
export function liveTestserverWorkflowGateway(options) {
|
|
36
|
+
return {
|
|
37
|
+
runs: async ({ repo, branch, token }) => {
|
|
38
|
+
const query = new URLSearchParams({ event: "pull_request", branch, per_page: String(RUNS_LISTED) });
|
|
39
|
+
const answered = await getJson(options, token, `repos/${repoPath(repo)}/actions/workflows/${TESTSERVER_WORKFLOW}/runs?${query.toString()}`, runsSchema);
|
|
40
|
+
if (!answered.ok)
|
|
41
|
+
return answered;
|
|
42
|
+
const runs = answered.value.workflow_runs.map((run) => ({
|
|
43
|
+
id: run.id,
|
|
44
|
+
headSha: run.head_sha,
|
|
45
|
+
createdAt: run.created_at,
|
|
46
|
+
}));
|
|
47
|
+
return { ok: true, runs };
|
|
48
|
+
},
|
|
49
|
+
publishedBuild: async ({ repo, runId, token }) => {
|
|
50
|
+
const jobs = await getJson(options, token, `repos/${repoPath(repo)}/actions/runs/${runId}/jobs`, jobsSchema);
|
|
51
|
+
if (!jobs.ok)
|
|
52
|
+
return jobs;
|
|
53
|
+
const job = jobs.value.jobs.find(({ name }) => name === BUNDLE_JOB);
|
|
54
|
+
if (job === undefined || job.conclusion !== "success")
|
|
55
|
+
return { ok: true, build: undefined };
|
|
56
|
+
const log = await getRedirectedText({ origin: options.origin, timeoutMs: options.logTimeoutMs }, token, `repos/${repoPath(repo)}/actions/jobs/${job.id}/logs`);
|
|
57
|
+
if (!log.ok)
|
|
58
|
+
return log;
|
|
59
|
+
const match = BUNDLE_LINE.exec(log.value);
|
|
60
|
+
const [, pr, name] = match ?? [];
|
|
61
|
+
return { ok: true, build: pr === undefined || name === undefined ? undefined : { pr: Number(pr), name } };
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -36,6 +36,11 @@ declare const schema: z.ZodObject<{
|
|
|
36
36
|
build: z.ZodObject<{
|
|
37
37
|
requested: z.ZodString;
|
|
38
38
|
resolved: z.ZodNullable<z.ZodString>;
|
|
39
|
+
pullRequest: z.ZodNullable<z.ZodObject<{
|
|
40
|
+
repo: z.ZodString;
|
|
41
|
+
number: z.ZodNumber;
|
|
42
|
+
headSha: z.ZodString;
|
|
43
|
+
}, z.core.$strip>>;
|
|
39
44
|
}, z.core.$strip>;
|
|
40
45
|
sandboxes: z.ZodArray<z.ZodObject<{
|
|
41
46
|
testserverUrl: z.ZodString;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// how outcomes report a failed create and an unpooled Testserver sandbox, which its errors (`command.ts`) report too.
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { describeCredentialFailure } from "../../credential/index.js";
|
|
6
|
-
import { createFailureText, describeCreateFailure } from "./sandbox/index.js";
|
|
6
|
+
import { createFailureText, describeCreateFailure, TESTSERVER_REPO } from "./sandbox/index.js";
|
|
7
7
|
const createFailureKinds = [
|
|
8
8
|
"connect-failed",
|
|
9
9
|
"http-error",
|
|
@@ -35,10 +35,20 @@ export function failedCreateFacts(failures) {
|
|
|
35
35
|
const schema = z.object({
|
|
36
36
|
/** What the build setting asked for and the build it resolved to. */
|
|
37
37
|
build: z.object({
|
|
38
|
-
/** The build or build
|
|
38
|
+
/** The build, build channel or PR build reference (pr:<N>) the build setting gave. */
|
|
39
39
|
requested: z.string(),
|
|
40
40
|
/** The build it resolved to; null when a build channel couldn't be resolved and was matched as written. */
|
|
41
41
|
resolved: z.string().nullable(),
|
|
42
|
+
/** For a PR build reference, the pull request and the head commit the resolved PR build was made from; null otherwise. */
|
|
43
|
+
pullRequest: z
|
|
44
|
+
.object({
|
|
45
|
+
/** The repository, vercel/api. */
|
|
46
|
+
repo: z.string(),
|
|
47
|
+
number: z.number(),
|
|
48
|
+
/** The pull request's head commit when the run started, 40 hex characters. */
|
|
49
|
+
headSha: z.string(),
|
|
50
|
+
})
|
|
51
|
+
.nullable(),
|
|
42
52
|
}),
|
|
43
53
|
/** The sandbox list: reused Testserver sandboxes first, freshest first, then created ones. */
|
|
44
54
|
sandboxes: z.array(z.object({
|
|
@@ -75,7 +85,13 @@ export const testserverPoolRanReport = {
|
|
|
75
85
|
facts: (facts, request) => {
|
|
76
86
|
const { resolution, sandboxes } = facts;
|
|
77
87
|
return {
|
|
78
|
-
build: {
|
|
88
|
+
build: {
|
|
89
|
+
requested: request.build,
|
|
90
|
+
resolved: resolution.kind === "as-written" ? null : resolution.build,
|
|
91
|
+
pullRequest: resolution.kind === "pull-request"
|
|
92
|
+
? { repo: TESTSERVER_REPO, number: resolution.pr, headSha: resolution.headSha }
|
|
93
|
+
: null,
|
|
94
|
+
},
|
|
79
95
|
sandboxes: sandboxes.map(({ testserverUrl, logViewerUrl, origin }) => ({ testserverUrl, logViewerUrl, origin })),
|
|
80
96
|
reused: sandboxes.filter((sandbox) => sandbox.origin === "reused").length,
|
|
81
97
|
created: sandboxes.filter((sandbox) => sandbox.origin === "created").length,
|