@cnc-tools/storm 0.8.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/runs/facts.d.ts +2 -2
- package/dist/commands/runs/facts.js +1 -1
- package/dist/commands/runs/list/outcomes.js +1 -1
- package/dist/commands/runs/logs/outcomes.js +1 -1
- package/dist/commands/runs/show/outcomes.js +3 -3
- package/dist/resources/testserver/commands/create/command.d.ts +6 -4
- package/dist/resources/testserver/commands/create/command.js +15 -6
- package/dist/resources/testserver/events.d.ts +4 -2
- package/dist/resources/testserver/pool/create.d.ts +4 -1
- package/dist/resources/testserver/pool/create.js +3 -1
- package/dist/resources/testserver/pool/gateways.d.ts +6 -0
- package/dist/resources/testserver/pool/live/pool-records.js +6 -2
- package/dist/resources/testserver/pool/pull-request.d.ts +18 -11
- package/dist/resources/testserver/pool/pull-request.js +43 -10
- package/dist/resources/testserver/presentation.js +2 -1
- package/dist/resources/testserver/provider.js +15 -7
- package/package.json +2 -3
- package/skills/testserver-builds.md +4 -2
package/dist/build-info.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type StyledCell } from "@
|
|
2
|
-
import type { Intent } from "@
|
|
1
|
+
import { type StyledCell } from "@vercel/clinkr/vcli-kit";
|
|
2
|
+
import type { Intent } from "@vercel/clinkr/vcli-kit/theme";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import type { ListedRun, RunScope } from "./past-run.ts";
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// What `storm runs list`, `storm runs show` and `storm runs logs` report of a run, and the errors they
|
|
2
2
|
// share: shared schemas and the facts built from a past run, so the commands' JSON agree.
|
|
3
|
-
import { muted } from "@
|
|
3
|
+
import { muted } from "@vercel/clinkr/vcli-kit";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { RESOURCE_REPORTS } from "../../resources.js";
|
|
6
6
|
import { sandboxPage, snapshotPage } from "../dashboard.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { muted, path, renderOutcome, status } from "@
|
|
1
|
+
import { muted, path, renderOutcome, status } from "@vercel/clinkr/vcli-kit";
|
|
2
2
|
import { defineOutcomes } from "@vercel/clinkr";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { branchText, commandText, exitText, exitTone, runnerCell, runFactsSchema, runsUnreadable, scopeSchema, scopeText, startedText, tookText, totalsText, totalsTone, } from "../facts.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderOutcome } from "@
|
|
1
|
+
import { renderOutcome } from "@vercel/clinkr/vcli-kit";
|
|
2
2
|
import { defineOutcomes } from "@vercel/clinkr";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { LOG_STEPS, runNotFound, runsUnreadable, scopeSchema } from "../facts.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { capsFor } from "@
|
|
2
|
-
import { bold, paint } from "@
|
|
1
|
+
import { capsFor } from "@vercel/clinkr/vcli-kit";
|
|
2
|
+
import { bold, paint } from "@vercel/clinkr/vcli-kit/theme";
|
|
3
3
|
import { defineOutcomes } from "@vercel/clinkr";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { RESOURCE_REPORTS } from "../../../resources.js";
|
|
@@ -88,7 +88,7 @@ const WATERFALL_WIDTH = 80;
|
|
|
88
88
|
const LABEL_WIDTH = 16;
|
|
89
89
|
/** No color: the plain text a pipe, `--no-color` and a script reading stdout get. */
|
|
90
90
|
const NO_PAINT = { tone: (_intent, text) => text, strong: (text) => text };
|
|
91
|
-
/** The painter for `caps`:
|
|
91
|
+
/** The painter for `caps`: vcli-kit's palette, or no color at all when it has none. */
|
|
92
92
|
function painterFor(caps) {
|
|
93
93
|
if (caps.colorDepth === "none")
|
|
94
94
|
return NO_PAINT;
|
|
@@ -9,10 +9,12 @@ import type { TestserverCommandApp } from "../app.ts";
|
|
|
9
9
|
* the pool, unleased. In text output it reports each step, and each progress message the control plane sends, indented,
|
|
10
10
|
* as it arrives.
|
|
11
11
|
*
|
|
12
|
-
* A PR build reference (`pr:<N>`, or the vercel/api pull request's URL) is resolved first, as a run resolves it,
|
|
13
|
-
*
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
12
|
+
* A PR build reference (`pr:<N>`, or the vercel/api pull request's URL) is resolved first, as a run resolves it, with
|
|
13
|
+
* the host's GitHub token: the pull request's head commit from GitHub, then the PR build of a pool entry created for
|
|
14
|
+
* `pr:<N>` on that commit, or else the newest PR build vercel/api's `Testserver` workflow published from it. The
|
|
15
|
+
* Testserver sandbox is created on that PR build, and its pool entry records `pr:<N>` as its requested build and the
|
|
16
|
+
* head commit, so a later run on that head finds the PR build in the pool. A PR build reference that can't be resolved
|
|
17
|
+
* refuses, and nothing is created.
|
|
16
18
|
*
|
|
17
19
|
* Each setting comes from its flag, else `storm.config.ts` (found from the working directory), else its built-in
|
|
18
20
|
* default; `--scope` and `--project` have none, so one of the two must give them. `pool create` only ever makes
|
|
@@ -16,10 +16,12 @@ import { outcomes } from "./outcomes.js";
|
|
|
16
16
|
* the pool, unleased. In text output it reports each step, and each progress message the control plane sends, indented,
|
|
17
17
|
* as it arrives.
|
|
18
18
|
*
|
|
19
|
-
* A PR build reference (`pr:<N>`, or the vercel/api pull request's URL) is resolved first, as a run resolves it,
|
|
20
|
-
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
19
|
+
* A PR build reference (`pr:<N>`, or the vercel/api pull request's URL) is resolved first, as a run resolves it, with
|
|
20
|
+
* the host's GitHub token: the pull request's head commit from GitHub, then the PR build of a pool entry created for
|
|
21
|
+
* `pr:<N>` on that commit, or else the newest PR build vercel/api's `Testserver` workflow published from it. The
|
|
22
|
+
* Testserver sandbox is created on that PR build, and its pool entry records `pr:<N>` as its requested build and the
|
|
23
|
+
* head commit, so a later run on that head finds the PR build in the pool. A PR build reference that can't be resolved
|
|
24
|
+
* refuses, and nothing is created.
|
|
23
25
|
*
|
|
24
26
|
* Each setting comes from its flag, else `storm.config.ts` (found from the working directory), else its built-in
|
|
25
27
|
* default; `--scope` and `--project` have none, so one of the two must give them. `pool create` only ever makes
|
|
@@ -94,7 +96,7 @@ export function command(cmd) {
|
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
resolution = resolved.resolution;
|
|
97
|
-
await ui.progress?.(`${TESTSERVER_REPO}#${resolution.pr} at ${shortSha(resolution.headSha)} → build ${resolution.build}`);
|
|
99
|
+
await ui.progress?.(`${TESTSERVER_REPO}#${resolution.pr} at ${shortSha(resolution.headSha)} → build ${resolution.build}${resolution.from === "pool" ? " (from the pool)" : ""}`);
|
|
98
100
|
}
|
|
99
101
|
const build = resolution?.build ?? requestedBuild;
|
|
100
102
|
const got = await credential.get();
|
|
@@ -102,7 +104,14 @@ export function command(cmd) {
|
|
|
102
104
|
return credentialFailed(got.failure);
|
|
103
105
|
await ui.progress?.(`Creating a Testserver sandbox on ${build}…`);
|
|
104
106
|
const progress = ui.progress;
|
|
105
|
-
const created = await createPooledSandbox(app.context, {
|
|
107
|
+
const created = await createPooledSandbox(app.context, {
|
|
108
|
+
credential: got.credential,
|
|
109
|
+
build,
|
|
110
|
+
requestedBuild,
|
|
111
|
+
...(resolution === undefined ? {} : { headSha: resolution.headSha }),
|
|
112
|
+
ttlMinutes,
|
|
113
|
+
lease: false,
|
|
114
|
+
}, progress === undefined ? {} : { onProgress: (message) => progress(` ${message}`) });
|
|
106
115
|
const pullRequest = resolution === undefined ? null : { repo: TESTSERVER_REPO, number: resolution.pr, headSha: resolution.headSha };
|
|
107
116
|
switch (created.kind) {
|
|
108
117
|
case "pooled":
|
|
@@ -9,8 +9,9 @@ import type { BuildChannel } from "./sandbox/index.ts";
|
|
|
9
9
|
* - `old-channel-resolution`: under `noCreate`, a build channel resolved from a channel resolution `ageMinutes`
|
|
10
10
|
* old, past the hour a run trusts one for.
|
|
11
11
|
* - `pr-build-resolved`: the `build` setting was the PR build reference `pr:<pr>`, and the run resolved it to `build`,
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* a PR build made from the vercel/api pull request's head commit `headSha`, found on the newest matching pool entry
|
|
13
|
+
* (`from: "pool"`) or as the newest PR build from the runs of vercel/api's `Testserver` workflow (`from:
|
|
14
|
+
* "workflow"`); `merged` says whether the pull request has merged.
|
|
14
15
|
* - `leasing`: the run lists the pool on `match` and health-checks its free Testserver sandboxes, to lease up to
|
|
15
16
|
* `requested`.
|
|
16
17
|
* - `leased`: the pool's usable Testserver sandboxes were leased, up to `requested`.
|
|
@@ -35,6 +36,7 @@ export type TestserverPoolEvent = {
|
|
|
35
36
|
readonly headSha: string;
|
|
36
37
|
readonly build: string;
|
|
37
38
|
readonly merged: boolean;
|
|
39
|
+
readonly from: "pool" | "workflow";
|
|
38
40
|
} | {
|
|
39
41
|
readonly kind: "leasing";
|
|
40
42
|
readonly match: BuildMatch;
|
|
@@ -26,7 +26,8 @@ export type PooledCreateOutcome = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates one Testserver sandbox on `build` living `ttlMinutes` (see `createSandbox`) and adds it to the pool, its
|
|
28
28
|
* entry recording the TTL and `requestedBuild`, the build setting as written: for a build or build channel the same
|
|
29
|
-
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to
|
|
29
|
+
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to; for a PR build, also
|
|
30
|
+
* `headSha`, the head commit it was made from, by which a later resolution of `pr:<N>` finds it. Free, or, with
|
|
30
31
|
* `lease`, leased to this process, the lease written before the entry so no other run sees it free. Its
|
|
31
32
|
* `createdAt` is the clock when the create started, which underestimates the time it has left. The entry is
|
|
32
33
|
* written first, as soon as the Testserver sandbox exists; then, when `requestedBuild` is a build channel, the channel resolution
|
|
@@ -47,6 +48,8 @@ export declare function createPooledSandbox(context: {
|
|
|
47
48
|
readonly build: string;
|
|
48
49
|
/** What the build setting asked for, which the pool entry records as its requested build. */
|
|
49
50
|
readonly requestedBuild: string;
|
|
51
|
+
/** For a PR build reference, the head commit the PR build `build` was made from, which the pool entry records. */
|
|
52
|
+
readonly headSha?: string;
|
|
50
53
|
readonly ttlMinutes: number;
|
|
51
54
|
readonly lease: boolean;
|
|
52
55
|
}, progress?: CreateProgress): Promise<PooledCreateOutcome>;
|
|
@@ -3,7 +3,8 @@ import { sandboxHost } from "./host.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates one Testserver sandbox on `build` living `ttlMinutes` (see `createSandbox`) and adds it to the pool, its
|
|
5
5
|
* entry recording the TTL and `requestedBuild`, the build setting as written: for a build or build channel the same
|
|
6
|
-
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to
|
|
6
|
+
* as `build`, for a PR build reference `pr:<N>` while `build` is the PR build it resolved to; for a PR build, also
|
|
7
|
+
* `headSha`, the head commit it was made from, by which a later resolution of `pr:<N>` finds it. Free, or, with
|
|
7
8
|
* `lease`, leased to this process, the lease written before the entry so no other run sees it free. Its
|
|
8
9
|
* `createdAt` is the clock when the create started, which underestimates the time it has left. The entry is
|
|
9
10
|
* written first, as soon as the Testserver sandbox exists; then, when `requestedBuild` is a build channel, the channel resolution
|
|
@@ -32,6 +33,7 @@ export async function createPooledSandbox(context, request, progress = {}) {
|
|
|
32
33
|
ttlMinutes,
|
|
33
34
|
requestedBuild: request.requestedBuild,
|
|
34
35
|
resolvedBuild,
|
|
36
|
+
...(request.headSha === undefined ? {} : { headSha: request.headSha }),
|
|
35
37
|
};
|
|
36
38
|
const leaseOptions = request.lease ? { lease: { startedAt: context.clock.now().toISOString() } } : {};
|
|
37
39
|
const added = await context.pool.addEntry(entry, leaseOptions);
|
|
@@ -12,6 +12,12 @@ export interface PoolEntry {
|
|
|
12
12
|
readonly ttlMinutes: number;
|
|
13
13
|
readonly requestedBuild: string;
|
|
14
14
|
readonly resolvedBuild: string;
|
|
15
|
+
/**
|
|
16
|
+
* For a Testserver sandbox on a PR build, created for the PR build reference `requestedBuild`, the pull request's
|
|
17
|
+
* head commit that PR build was made from, 40 lowercase hex characters; absent otherwise, and on entries written
|
|
18
|
+
* before storm recorded it.
|
|
19
|
+
*/
|
|
20
|
+
readonly headSha?: string;
|
|
15
21
|
}
|
|
16
22
|
/** A lease as its file records it: the process holding it, on which host, since when. */
|
|
17
23
|
export interface LeaseRecord {
|
|
@@ -9,6 +9,10 @@ const entrySchema = z.object({
|
|
|
9
9
|
ttlMinutes: z.number().int().positive(),
|
|
10
10
|
requestedBuild: z.string().min(1),
|
|
11
11
|
resolvedBuild: z.string().min(1),
|
|
12
|
+
headSha: z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^[0-9a-f]{40}$/)
|
|
15
|
+
.optional(),
|
|
12
16
|
});
|
|
13
17
|
const leaseSchema = z.object({
|
|
14
18
|
version: z.literal(1),
|
|
@@ -25,8 +29,8 @@ export function parseEntry(text) {
|
|
|
25
29
|
const parsed = parseVersioned(text, entrySchema);
|
|
26
30
|
if (!parsed.ok)
|
|
27
31
|
return parsed;
|
|
28
|
-
const { version: _version, ...entry } = parsed.value;
|
|
29
|
-
return { ok: true, value: entry };
|
|
32
|
+
const { version: _version, headSha, ...entry } = parsed.value;
|
|
33
|
+
return { ok: true, value: { ...entry, ...(headSha === undefined ? {} : { headSha }) } };
|
|
30
34
|
}
|
|
31
35
|
/** The lease a lease file holds, or why it holds none. */
|
|
32
36
|
export function parseLease(text) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GitHubFailure, GitHubTokenGateway, GitHubTokenOrigin, PullRequestGateway, TestserverWorkflowGateway } from "../pull-request/index.ts";
|
|
2
2
|
import type { Clock } from "../../../time/index.ts";
|
|
3
|
+
import type { PoolStoreGateway } from "./gateways.ts";
|
|
3
4
|
/** How long the Testserver control plane creates Testserver sandboxes from a PR build after it was published. */
|
|
4
5
|
export declare const PR_BUILD_LIFETIME_MS: number;
|
|
5
6
|
/**
|
|
@@ -41,8 +42,9 @@ export type PrBuildRefusal = {
|
|
|
41
42
|
readonly expiresAt: string;
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
|
-
* A PR build reference resolved: pull request `pr`'s head commit,
|
|
45
|
-
*
|
|
45
|
+
* A PR build reference resolved: pull request `pr`'s head commit, a PR build made from it, whether the pull request
|
|
46
|
+
* has merged, and where the PR build was found (`from`): `pool`, on the newest pool entry created for `pr:<pr>` on that
|
|
47
|
+
* head commit, or `workflow`, the newest PR build from the runs of vercel/api's `Testserver` workflow.
|
|
46
48
|
*/
|
|
47
49
|
export interface PrBuildResolution {
|
|
48
50
|
readonly kind: "pull-request";
|
|
@@ -50,6 +52,7 @@ export interface PrBuildResolution {
|
|
|
50
52
|
readonly headSha: string;
|
|
51
53
|
readonly build: string;
|
|
52
54
|
readonly merged: boolean;
|
|
55
|
+
readonly from: "pool" | "workflow";
|
|
53
56
|
}
|
|
54
57
|
/** How resolving a PR build reference ended. */
|
|
55
58
|
export type PrBuildOutcome = {
|
|
@@ -59,28 +62,32 @@ export type PrBuildOutcome = {
|
|
|
59
62
|
readonly ok: false;
|
|
60
63
|
readonly refusal: PrBuildRefusal;
|
|
61
64
|
};
|
|
62
|
-
/** What resolving a PR build reference reads: GitHub, with the host's GitHub token, and the clock. */
|
|
65
|
+
/** What resolving a PR build reference reads: GitHub, with the host's GitHub token, the pool, and the clock. */
|
|
63
66
|
export interface PrBuildContext {
|
|
67
|
+
readonly pool: PoolStoreGateway;
|
|
64
68
|
readonly pullRequests: PullRequestGateway;
|
|
65
69
|
readonly testserverWorkflow: TestserverWorkflowGateway;
|
|
66
70
|
readonly githubToken: GitHubTokenGateway;
|
|
67
71
|
readonly clock: Clock;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
|
-
* Resolves the PR build reference `pr:<pr>` to
|
|
71
|
-
*
|
|
74
|
+
* Resolves the PR build reference `pr:<pr>` to a PR build made from the pull request's current head commit: the PR
|
|
75
|
+
* build of the newest matching pool entry, or else the newest PR build the workflow published. In order, it:
|
|
72
76
|
*
|
|
73
77
|
* 1. finds a GitHub token on the host; with none it refuses (`pull-request-unreadable`, `no-token`);
|
|
74
78
|
* 2. reads the pull request's head commit and branch with it; a failure refuses (`pull-request-unreadable`);
|
|
75
|
-
* 3.
|
|
76
|
-
*
|
|
79
|
+
* 3. takes the PR build of the newest pool entry created for `pr:<pr>` on that head commit, when that PR build hasn't
|
|
80
|
+
* expired (`from: "pool"`); this reads nothing more from GitHub;
|
|
81
|
+
* 4. otherwise lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
|
|
82
|
+
* 5. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
|
|
77
83
|
* of this pull request; reading one failing refuses (`pr-builds-unlisted`), and with none it refuses
|
|
78
84
|
* (`pr-build-not-ready`), naming the newest PR build of the up to 3 newest runs for older head commits;
|
|
79
|
-
*
|
|
85
|
+
* 6. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
|
|
80
86
|
*
|
|
81
|
-
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it
|
|
82
|
-
*
|
|
83
|
-
*
|
|
87
|
+
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it; a pool
|
|
88
|
+
* entry records the head commit its PR build was made from, so the pool's is the head's too. It needs no credential:
|
|
89
|
+
* the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and writes no channel
|
|
90
|
+
* resolution: a PR build reference's head commit is read on every run.
|
|
84
91
|
*/
|
|
85
92
|
export declare function resolvePrBuild(context: PrBuildContext, request: {
|
|
86
93
|
readonly pr: number;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { TESTSERVER_REPO } from "../sandbox/index.js";
|
|
1
|
+
import { buildReferenceText, TESTSERVER_REPO } from "../sandbox/index.js";
|
|
2
2
|
/** How long the Testserver control plane creates Testserver sandboxes from a PR build after it was published. */
|
|
3
3
|
export const PR_BUILD_LIFETIME_MS = 7 * 24 * 60 * 60 * 1000;
|
|
4
4
|
/** How many runs for older head commits a refusal reads, newest first, to name the newest PR build. */
|
|
5
5
|
const OLDER_RUNS_READ = 3;
|
|
6
6
|
/**
|
|
7
|
-
* Resolves the PR build reference `pr:<pr>` to
|
|
8
|
-
*
|
|
7
|
+
* Resolves the PR build reference `pr:<pr>` to a PR build made from the pull request's current head commit: the PR
|
|
8
|
+
* build of the newest matching pool entry, or else the newest PR build the workflow published. In order, it:
|
|
9
9
|
*
|
|
10
10
|
* 1. finds a GitHub token on the host; with none it refuses (`pull-request-unreadable`, `no-token`);
|
|
11
11
|
* 2. reads the pull request's head commit and branch with it; a failure refuses (`pull-request-unreadable`);
|
|
12
|
-
* 3.
|
|
13
|
-
*
|
|
12
|
+
* 3. takes the PR build of the newest pool entry created for `pr:<pr>` on that head commit, when that PR build hasn't
|
|
13
|
+
* expired (`from: "pool"`); this reads nothing more from GitHub;
|
|
14
|
+
* 4. otherwise lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
|
|
15
|
+
* 5. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
|
|
14
16
|
* of this pull request; reading one failing refuses (`pr-builds-unlisted`), and with none it refuses
|
|
15
17
|
* (`pr-build-not-ready`), naming the newest PR build of the up to 3 newest runs for older head commits;
|
|
16
|
-
*
|
|
18
|
+
* 6. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
|
|
17
19
|
*
|
|
18
|
-
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* GitHub's runs carry the head commit each was for, so the PR build is the head's however the workflow built it; a pool
|
|
21
|
+
* entry records the head commit its PR build was made from, so the pool's is the head's too. It needs no credential:
|
|
22
|
+
* the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and writes no channel
|
|
23
|
+
* resolution: a PR build reference's head commit is read on every run.
|
|
21
24
|
*/
|
|
22
25
|
export async function resolvePrBuild(context, request) {
|
|
23
26
|
const { pr } = request;
|
|
@@ -31,6 +34,9 @@ export async function resolvePrBuild(context, request) {
|
|
|
31
34
|
refusal: { kind: "pull-request-unreadable", pr, failure: read.failure, tokenOrigin: token.origin },
|
|
32
35
|
};
|
|
33
36
|
const { headSha, headRef, merged } = read.head;
|
|
37
|
+
const pooled = await pooledPrBuild(context, pr, headSha);
|
|
38
|
+
if (pooled !== undefined)
|
|
39
|
+
return { ok: true, resolution: { kind: "pull-request", pr, headSha, build: pooled, merged, from: "pool" } };
|
|
34
40
|
const listed = await context.testserverWorkflow.runs({ repo: TESTSERVER_REPO, branch: headRef, token: token.token });
|
|
35
41
|
if (!listed.ok)
|
|
36
42
|
return { ok: false, refusal: { kind: "pr-builds-unlisted", pr, failure: listed.failure } };
|
|
@@ -47,7 +53,10 @@ export async function resolvePrBuild(context, request) {
|
|
|
47
53
|
ok: false,
|
|
48
54
|
refusal: { kind: "pr-build-expired", pr, headSha, build: found.build.name, expiresAt },
|
|
49
55
|
};
|
|
50
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
resolution: { kind: "pull-request", pr, headSha, build: found.build.name, merged, from: "workflow" },
|
|
59
|
+
};
|
|
51
60
|
}
|
|
52
61
|
let newest;
|
|
53
62
|
for (const run of listed.runs.filter((each) => each.headSha !== headSha).slice(0, OLDER_RUNS_READ)) {
|
|
@@ -61,6 +70,30 @@ export async function resolvePrBuild(context, request) {
|
|
|
61
70
|
}
|
|
62
71
|
return { ok: false, refusal: { kind: "pr-build-not-ready", pr, headSha, newest } };
|
|
63
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* The PR build of the newest pool entry created for `pr:<pr>` on head commit `headSha`, leased or free, by when the
|
|
75
|
+
* entry was created; undefined when there is none, when the pool can't be listed, or when that PR build has expired
|
|
76
|
+
* or its name gives no time, so the runs decide. An entry written before storm recorded head commits has none, so it
|
|
77
|
+
* is never one.
|
|
78
|
+
*/
|
|
79
|
+
async function pooledPrBuild(context, pr, headSha) {
|
|
80
|
+
const listed = await context.pool.listEntries();
|
|
81
|
+
if (!listed.ok)
|
|
82
|
+
return undefined;
|
|
83
|
+
const requested = buildReferenceText({ kind: "pull-request", number: pr });
|
|
84
|
+
const newest = listed.value.entries
|
|
85
|
+
.map(({ entry }) => entry)
|
|
86
|
+
.filter((entry) => entry.requestedBuild === requested && entry.headSha === headSha)
|
|
87
|
+
.toSorted((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))[0];
|
|
88
|
+
if (newest === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
const publishedAt = buildTime(newest.resolvedBuild);
|
|
91
|
+
if (publishedAt === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
return Date.parse(publishedAt) + PR_BUILD_LIFETIME_MS > context.clock.now().getTime()
|
|
94
|
+
? newest.resolvedBuild
|
|
95
|
+
: undefined;
|
|
96
|
+
}
|
|
64
97
|
/**
|
|
65
98
|
* The PR build of pull request `pr` that `run` published, with when it was published: the time its name starts with,
|
|
66
99
|
* or, for a name without one, when the run started. A build another pull request's run published, from a branch of
|
|
@@ -51,8 +51,9 @@ function oldChannelResolutionText(event) {
|
|
|
51
51
|
}
|
|
52
52
|
/** A PR build reference resolved: the pull request, its head commit's short form and the PR build. */
|
|
53
53
|
function prBuildResolvedText(event) {
|
|
54
|
+
const pooled = event.from === "pool" ? " (from the pool)" : "";
|
|
54
55
|
const merged = event.merged ? " (merged; latest_main or stable may have it)" : "";
|
|
55
|
-
return `Build: ${TESTSERVER_REPO}#${event.pr} at ${shortSha(event.headSha)} → ${event.build}${merged}`;
|
|
56
|
+
return `Build: ${TESTSERVER_REPO}#${event.pr} at ${shortSha(event.headSha)} → ${event.build}${pooled}${merged}`;
|
|
56
57
|
}
|
|
57
58
|
function unresolvedWhy(reason) {
|
|
58
59
|
switch (reason.kind) {
|
|
@@ -158,8 +158,7 @@ async function provision(context, request, create, signal, progress, held) {
|
|
|
158
158
|
return canceled();
|
|
159
159
|
const { rejected, credentialFailure, uncreatedCount, ...made } = await createMissing(context, {
|
|
160
160
|
source: create.source,
|
|
161
|
-
|
|
162
|
-
requestedBuild: request.build,
|
|
161
|
+
target: createTarget(request.build, resolution),
|
|
163
162
|
ttlMinutes: create.ttlMinutes,
|
|
164
163
|
count: missing,
|
|
165
164
|
}, signal, progress, held);
|
|
@@ -210,10 +209,19 @@ async function resolvePullRequestBuild(context, pr, progress) {
|
|
|
210
209
|
if (!outcome.ok)
|
|
211
210
|
return outcome.refusal;
|
|
212
211
|
const { resolution } = outcome;
|
|
213
|
-
const { headSha, build, merged } = resolution;
|
|
214
|
-
await progress.emit({ kind: "pr-build-resolved", pr, headSha, build, merged });
|
|
212
|
+
const { headSha, build, merged, from } = resolution;
|
|
213
|
+
await progress.emit({ kind: "pr-build-resolved", pr, headSha, build, merged, from });
|
|
215
214
|
return { kind: "resolved", resolution };
|
|
216
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
|
+
}
|
|
217
225
|
/**
|
|
218
226
|
* Creates `count` Testserver sandboxes, 8 at a time, each leased as it exists. It asks `source` for a credential
|
|
219
227
|
* once before it reports the creates, so a source that can't give one stops it before any create, with every create
|
|
@@ -227,7 +235,7 @@ async function resolvePullRequestBuild(context, pr, progress) {
|
|
|
227
235
|
* first failure, if any, and `uncreatedCount` how many creates never ran.
|
|
228
236
|
*/
|
|
229
237
|
async function createMissing(context, request, signal, progress, held) {
|
|
230
|
-
const { source,
|
|
238
|
+
const { source, target, ttlMinutes, count } = request;
|
|
231
239
|
const first = await source.get();
|
|
232
240
|
if (!first.ok)
|
|
233
241
|
return {
|
|
@@ -238,7 +246,7 @@ async function createMissing(context, request, signal, progress, held) {
|
|
|
238
246
|
credentialFailure: first.failure,
|
|
239
247
|
uncreatedCount: count,
|
|
240
248
|
};
|
|
241
|
-
await progress.emit({ kind: "creating", count, build });
|
|
249
|
+
await progress.emit({ kind: "creating", count, build: target.build });
|
|
242
250
|
let rejected;
|
|
243
251
|
let credentialFailure;
|
|
244
252
|
const mayCreate = () => rejected === undefined && credentialFailure === undefined && !signal.aborted;
|
|
@@ -253,7 +261,7 @@ async function createMissing(context, request, signal, progress, held) {
|
|
|
253
261
|
return undefined;
|
|
254
262
|
const { credential } = got;
|
|
255
263
|
await progress.emit({ kind: "create-started", index, count });
|
|
256
|
-
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 }) });
|
|
257
265
|
if (outcome.kind === "pooled")
|
|
258
266
|
held.push(outcome.host);
|
|
259
267
|
if (outcome.kind === "create-failed" && outcome.failure.kind === "rejected")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnc-tools/storm",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Run a command against Vercel Testserver sandboxes",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -90,8 +90,7 @@
|
|
|
90
90
|
"registry": "https://registry.npmjs.org/"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"@
|
|
94
|
-
"@vercel/clinkr": "npm:clinkr@^0.9.1",
|
|
93
|
+
"@vercel/clinkr": "npm:clinkr@^0.10.0",
|
|
95
94
|
"@vercel/sandbox": "3.9.0",
|
|
96
95
|
"zod": "^4.6.5"
|
|
97
96
|
},
|
|
@@ -18,9 +18,9 @@ Use this skill to choose the Testserver build of a run. Use it also when a chang
|
|
|
18
18
|
- The **head commit** of a pull request is the newest commit on its branch, such as `87343a6781b4f540893958e49e8eedaf5bb2b4ad`. Each PR build comes from the workflow run for one head commit.
|
|
19
19
|
- A **PR build reference** gives a vercel/api pull request as the build. Write it as `pr:<N>`, such as `pr:104196`, or as the URL of the pull request, such as `https://github.com/vercel/api/pull/104196`. storm changes the URL to `pr:<N>`.
|
|
20
20
|
|
|
21
|
-
A run with `pr:<N>` uses
|
|
21
|
+
A run with `pr:<N>` uses a PR build of the head commit of the pull request. If no PR build of that head commit exists, the run stops. It does not wait, and it does not use a PR build of an older head commit.
|
|
22
22
|
|
|
23
|
-
storm reads the head commit
|
|
23
|
+
storm reads the head commit from GitHub on this machine. If the pool has a Testserver sandbox that was made for `pr:<N>` on the head commit, storm uses the PR build of the newest such Testserver sandbox. It does this only if that PR build has not expired. Then storm reads only the head commit from GitHub. If the workflow ran again on the same head commit, storm can use an older PR build of that head commit from the pool. If the pool has no usable PR build, storm reads the runs of the `Testserver` workflow and uses the newest PR build of the head commit. storm uses the first GitHub token that it finds: `GITHUB_TOKEN`, `GH_TOKEN`, or the output of `gh auth token`. The token must be able to read vercel/api and its Actions. The token stays on this machine.
|
|
24
24
|
|
|
25
25
|
## Choose a build
|
|
26
26
|
|
|
@@ -48,6 +48,8 @@ To make one Testserver sandbox on the PR build, run `storm pool create --build p
|
|
|
48
48
|
|
|
49
49
|
With `--testserver-no-create`, a run with `pr:<N>` uses only the Testserver sandboxes in the pool on that PR build. It does not make new ones.
|
|
50
50
|
|
|
51
|
+
To make runs more reliable, for example before a demo, make the Testserver sandboxes first. Run `storm pool create --build pr:<N> --json` one time for each Testserver sandbox. Then a run with `pr:<N>` reads only the head commit from GitHub. Its line `Build: …` ends with `(from the pool)`. A Testserver sandbox lives for its TTL, 5 hours or less. After a new push to the pull request, the runs do not use these Testserver sandboxes.
|
|
52
|
+
|
|
51
53
|
## If a run stops
|
|
52
54
|
|
|
53
55
|
Read `reason` in the error document. Read the facts of the error in `data`.
|