@cnc-tools/storm 0.8.0 → 0.9.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.
Files changed (50) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/commands/exec/command.d.ts +32 -0
  3. package/dist/commands/exec/metadata.js +1 -1
  4. package/dist/commands/exec/outcomes.d.ts +67 -0
  5. package/dist/commands/exec/outcomes.js +50 -0
  6. package/dist/commands/exec/run-command.d.ts +17 -11
  7. package/dist/commands/exec/run-command.js +33 -16
  8. package/dist/commands/runs/facts.d.ts +2 -2
  9. package/dist/commands/runs/facts.js +1 -1
  10. package/dist/commands/runs/list/outcomes.js +1 -1
  11. package/dist/commands/runs/logs/outcomes.js +1 -1
  12. package/dist/commands/runs/show/outcomes.js +3 -3
  13. package/dist/commands/vitest/command.d.ts +32 -0
  14. package/dist/commands/vitest/outcomes.d.ts +16 -0
  15. package/dist/core/run.d.ts +6 -1
  16. package/dist/core/run.js +1 -1
  17. package/dist/resources/testserver/commands/create/command.d.ts +6 -4
  18. package/dist/resources/testserver/commands/create/command.js +15 -6
  19. package/dist/resources/testserver/events.d.ts +4 -2
  20. package/dist/resources/testserver/pool/create.d.ts +4 -1
  21. package/dist/resources/testserver/pool/create.js +3 -1
  22. package/dist/resources/testserver/pool/gateways.d.ts +6 -0
  23. package/dist/resources/testserver/pool/live/pool-records.js +6 -2
  24. package/dist/resources/testserver/pool/pull-request.d.ts +18 -11
  25. package/dist/resources/testserver/pool/pull-request.js +43 -10
  26. package/dist/resources/testserver/presentation.js +2 -1
  27. package/dist/resources/testserver/provider.js +15 -7
  28. package/dist/runner/index.d.ts +2 -1
  29. package/dist/runner/index.js +1 -0
  30. package/dist/runner/prepare.d.ts +7 -6
  31. package/dist/runner/prepare.js +1 -1
  32. package/dist/runner/ready.d.ts +6 -0
  33. package/dist/runner/ready.js +33 -5
  34. package/dist/runner/recipe.d.ts +33 -6
  35. package/dist/runner/recipe.js +150 -22
  36. package/dist/runner/secrets.d.ts +42 -0
  37. package/dist/runner/secrets.js +44 -0
  38. package/dist/runner/snapshot-build.d.ts +5 -2
  39. package/dist/runner/snapshot-build.js +12 -5
  40. package/dist/runner/snapshot-cache.d.ts +3 -3
  41. package/dist/runner/snapshot-cache.js +2 -2
  42. package/dist/runner/snapshot-key.d.ts +19 -12
  43. package/dist/runner/snapshot-key.js +25 -16
  44. package/dist/runner/snapshot-save.d.ts +5 -3
  45. package/dist/runner/snapshot-save.js +7 -5
  46. package/dist/runner/steps.d.ts +6 -1
  47. package/dist/runner/steps.js +5 -2
  48. package/package.json +2 -3
  49. package/skills/overview.md +1 -0
  50. package/skills/testserver-builds.md +4 -2
@@ -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, from
20
- * GitHub with the host's GitHub token: the pull request's head commit, then the newest PR build vercel/api's
21
- * `Testserver` workflow published from it. The Testserver sandbox is created on that PR build, and its pool entry records `pr:<N>` as
22
- * its requested build. A PR build reference that can't be resolved refuses, and nothing is created.
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, { credential: got.credential, build, requestedBuild, ttlMinutes, lease: false }, progress === undefined ? {} : { onProgress: (message) => progress(` ${message}`) });
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
- * the newest PR build made from the vercel/api pull request's head commit `headSha`; `merged` says whether the pull
13
- * request has merged.
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. Free, or, with
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. Free, or, with
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, the newest PR build made from it, and whether the
45
- * pull request has merged.
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 the newest PR build made from the pull request's current head commit,
71
- * from GitHub alone. In order, it:
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. lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
76
- * 4. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
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
- * 5. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
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. It
82
- * needs no credential: the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and
83
- * writes no channel resolution: a PR build reference is resolved on every run.
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 the newest PR build made from the pull request's current head commit,
8
- * from GitHub alone. In order, it:
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. lists the runs of vercel/api's `Testserver` workflow on that branch; a failure refuses (`pr-builds-unlisted`);
13
- * 4. takes, of the runs for the head commit, newest first, the first whose `Bundle & Publish` job published a PR build
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
- * 5. refuses one published 7 days ago or more, by the time its name gives (`pr-build-expired`).
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. It
19
- * needs no credential: the Testserver control plane isn't asked. The GitHub token goes only to GitHub. It reads and
20
- * writes no channel resolution: a PR build reference is resolved on every run.
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 { ok: true, resolution: { kind: "pull-request", pr, headSha, build: found.build.name, merged } };
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
- build: resolution.kind === "pull-request" ? resolution.build : request.build,
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, build, requestedBuild, ttlMinutes, count } = request;
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, build, requestedBuild, ttlMinutes, lease: true }, { onProgress: (message) => progress.emit({ kind: "create-progress", index, count, message }) });
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")
@@ -10,8 +10,9 @@ export { liveRunnerSnapshotCacheGateway, type LiveRunnerSnapshotCacheOptions, un
10
10
  export { lineSplitter, type LineSplitter, OUTPUT_TAIL_LINES, outputRule, outputTail, type OutputTail, rewritePaths, splitLines, } from "./output.ts";
11
11
  export { type PreparedRunner, prepareRunner, type PrepareRunnerOutcome, type PrepareRunnerRequest, type RunnerPrepareContext, } from "./prepare.ts";
12
12
  export { APPLY_LABEL, type ReadyRunner, readyRunner, type ReadyRunnerOutcome, type ReadyRunnerRequest, } from "./ready.ts";
13
- export { type CheckedRecipe, checkRecipe, type RecipeCheck, type RecipeProblem, resolveSteps, resolveVcpus, type RunnerRecipe, type RunnerResources, type RunnerStep, type RunnerStepContext, type RunnerSteps, } from "./recipe.ts";
13
+ export { type CheckedRecipe, checkRecipe, type RecipeCheck, type RecipeProblem, resolveSteps, resolveVcpus, type RunnerRecipe, type RunnerResources, type ResolvedRunnerStep, type RunnerStep, type RunnerStepContext, type RunnerSteps, } from "./recipe.ts";
14
14
  export { REMOTE_TEST_EVENTS_PATH, type RemoteCommandOutcome, remoteCommand, remoteEnvironment, type RemoteTestEvents, runRemote, } from "./remote-command.ts";
15
+ export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, stepSecrets, type RunnerSecretProblem, type RunnerSecrets, type RunnerSecretsRead, } from "./secrets.ts";
15
16
  export { CREATE_SETTLE_MS, keptMs, type RunnerSandboxPlan, type RunnerSandboxScope, runnerSandboxScope, type RunnerScopeReport, SNAPSHOT_SETTLE_MS, } from "./scope.ts";
16
17
  export { BASE_INDEX_LABEL, buildSnapshot, type BuildSnapshotRequest, type BuiltSnapshot } from "./snapshot-build.ts";
17
18
  export { dropBranchSnapshots, type DroppedBranchSnapshots, findSnapshotCandidates, isBranchEntry, pickSnapshot, RUNNER_SNAPSHOTS_SUBPATH, type RunnerSnapshotCandidate, SNAPSHOT_EXPIRATION_MS, type SnapshotCacheContext, type SnapshotCacheNote, snapshotEntryFileName, snapshotEntryIdentity, } from "./snapshot-cache.ts";
@@ -11,6 +11,7 @@ export { prepareRunner, } from "./prepare.js";
11
11
  export { APPLY_LABEL, readyRunner, } from "./ready.js";
12
12
  export { checkRecipe, resolveSteps, resolveVcpus, } from "./recipe.js";
13
13
  export { REMOTE_TEST_EVENTS_PATH, remoteCommand, remoteEnvironment, runRemote, } from "./remote-command.js";
14
+ export { readRunnerSecrets, RUNNER_SECRET_MIN_LENGTH, stepSecrets, } from "./secrets.js";
14
15
  export { CREATE_SETTLE_MS, keptMs, runnerSandboxScope, SNAPSHOT_SETTLE_MS, } from "./scope.js";
15
16
  export { BASE_INDEX_LABEL, buildSnapshot } from "./snapshot-build.js";
16
17
  export { dropBranchSnapshots, findSnapshotCandidates, isBranchEntry, pickSnapshot, RUNNER_SNAPSHOTS_SUBPATH, SNAPSHOT_EXPIRATION_MS, snapshotEntryFileName, snapshotEntryIdentity, } from "./snapshot-cache.js";
@@ -1,6 +1,6 @@
1
1
  import { type RefusedBaseRef } from "./base.ts";
2
2
  import type { CheckoutFailure, CheckoutHead, CheckoutUpload } from "./gateways.ts";
3
- import { type CheckedRecipe, type RunnerResources, type RunnerStep } from "./recipe.ts";
3
+ import { type CheckedRecipe, type ResolvedRunnerStep, type RunnerResources } from "./recipe.ts";
4
4
  import { type RunnerSnapshotCandidate, type SnapshotCacheContext, type SnapshotCacheNote } from "./snapshot-cache.ts";
5
5
  /** What `prepareRunner` needs: the checkout, the runner snapshot cache and the clock. */
6
6
  export type RunnerPrepareContext = SnapshotCacheContext;
@@ -24,9 +24,9 @@ export interface PreparedRunner {
24
24
  /** The run's base, a full SHA, and the ref it is HEAD's merge-base with. */
25
25
  readonly base: string;
26
26
  readonly baseRef: string;
27
- /** The recipe's snapshot steps at the base, and their snapshot key. */
28
- readonly toolchains: readonly RunnerStep[];
29
- readonly warm: readonly RunnerStep[];
27
+ /** The recipe's snapshot steps at the base, each with the runner secret names it gets, and their snapshot key. */
28
+ readonly toolchains: readonly ResolvedRunnerStep[];
29
+ readonly prebuild: readonly ResolvedRunnerStep[];
30
30
  readonly snapshotKey: string;
31
31
  /** The runner sandbox's vCPUs for the run's resources. */
32
32
  readonly vcpus: number;
@@ -57,8 +57,9 @@ export interface PreparedRunner {
57
57
  * - `ok`: the run is ready for the remote side.
58
58
  * - `no-base-ref`: no ref in `baseRefs` exists locally and shares history with HEAD; `refs` says why for each.
59
59
  * - `submodules`: the checkout has Git submodules, at `paths`.
60
- * - `invalid-recipe`: a step function or `vcpus` failed or returned something storm can't use, at the run's
61
- * base or for its resources; `path` is the key inside the recipe.
60
+ * - `invalid-recipe`: a step function or `vcpus` failed or returned something storm can't use, such as a step naming
61
+ * a runner secret the recipe's `secrets` doesn't declare, at the run's base or for its resources; `path` is the key
62
+ * inside the recipe.
62
63
  * - `checkout-failed`: git or tar failed, such as outside a Git checkout.
63
64
  */
64
65
  export type PrepareRunnerOutcome = {
@@ -52,7 +52,7 @@ export async function prepareRunner(context, request) {
52
52
  base,
53
53
  baseRef: resolved.ref,
54
54
  toolchains: steps.toolchains,
55
- warm: steps.warm,
55
+ prebuild: steps.prebuild,
56
56
  snapshotKey: steps.key,
57
57
  vcpus: vcpus.vcpus,
58
58
  upload: upload.value,
@@ -3,6 +3,7 @@ import type { RunnerFailure, RunnerProgress } from "./events.ts";
3
3
  import type { CheckoutUpload, RunnerSandbox, RunnerSnapshotCacheFailure, RunnerSnapshotEntry, SandboxAccess, StagedFile } from "./gateways.ts";
4
4
  import type { PreparedRunner } from "./prepare.ts";
5
5
  import type { RunnerSandboxScope } from "./scope.ts";
6
+ import { type RunnerSecrets } from "./secrets.ts";
6
7
  /** The label of the step that applies and commits the run's changes in the runner sandbox. */
7
8
  export declare const APPLY_LABEL = "Applying your changes";
8
9
  /** A runner sandbox ready for the command. */
@@ -58,6 +59,11 @@ export interface ReadyRunnerRequest {
58
59
  readonly access: SandboxAccess;
59
60
  /** The local user, for each sandbox's `user` tag. */
60
61
  readonly user: string;
62
+ /**
63
+ * Every runner secret's value, of which each recipe step, in a snapshot build or the install and build, gets the
64
+ * ones it names.
65
+ */
66
+ readonly secrets: RunnerSecrets;
61
67
  }
62
68
  /**
63
69
  * Readies the runner sandbox for a prepared run. Of the cached candidates for the access's team and project, it
@@ -2,6 +2,7 @@
2
2
  // or build one, start the runner sandbox from it, upload and apply the run's changes, then install and build.
3
3
  import { posix } from "node:path";
4
4
  import { runnerTags } from "./context.js";
5
+ import { stepSecrets } from "./secrets.js";
5
6
  import { buildSnapshot } from "./snapshot-build.js";
6
7
  import { pickSnapshot } from "./snapshot-cache.js";
7
8
  import { applyScript, REMOTE_ROOT, STAGED_FILES } from "./snapshot-key.js";
@@ -33,7 +34,13 @@ export async function readyRunner(context, request, control, progress) {
33
34
  });
34
35
  }
35
36
  else {
36
- const built = await buildSnapshot(context, { prepared, access, user: request.user, reason: prepared.rebuild ? "rebuild" : "no-snapshot" }, control, progress);
37
+ const built = await buildSnapshot(context, {
38
+ prepared,
39
+ access,
40
+ user: request.user,
41
+ secrets: request.secrets,
42
+ reason: prepared.rebuild ? "rebuild" : "no-snapshot",
43
+ }, control, progress);
37
44
  if (built.kind !== "ok")
38
45
  return built;
39
46
  entry = built.value.entry;
@@ -79,10 +86,22 @@ export async function readyRunner(context, request, control, progress) {
79
86
  const loginPath = await context.runnerSandboxes.loginPath(sandbox, signal);
80
87
  if (!loginPath.ok)
81
88
  return sandboxStop("login-path", loginPath.failure);
82
- const installed = await stage(context, { sandbox, phase: "install", step: recipe.run.install, region: recipe.region }, signal, progress);
89
+ const installed = await stage(context, {
90
+ sandbox,
91
+ phase: "install",
92
+ step: recipe.run.install,
93
+ secrets: stepSecrets(request.secrets, recipe.run.install.secrets),
94
+ region: recipe.region,
95
+ }, signal, progress);
83
96
  if (installed.kind !== "ok")
84
97
  return installed;
85
- const built = await stage(context, { sandbox, phase: "build", step: recipe.run.build, region: recipe.region }, signal, progress);
98
+ const built = await stage(context, {
99
+ sandbox,
100
+ phase: "build",
101
+ step: recipe.run.build,
102
+ secrets: stepSecrets(request.secrets, recipe.run.build.secrets),
103
+ region: recipe.region,
104
+ }, signal, progress);
86
105
  if (built.kind !== "ok")
87
106
  return built;
88
107
  return {
@@ -139,7 +158,10 @@ export function stagedChanges(upload) {
139
158
  : [{ name: STAGED_FILES.untrackedTarball, content: upload.untrackedTarball }]),
140
159
  ];
141
160
  }
142
- /** Runs the apply, install or build step, answering how long it took; the install and build get rule lines. */
161
+ /**
162
+ * Runs the apply, install or build step with `secrets`, the runner secrets the recipe's install or build step names
163
+ * (none for the apply, storm's own), answering how long it took; the install and build get rule lines.
164
+ */
143
165
  async function stage(context, request, signal, progress) {
144
166
  if (signal.aborted)
145
167
  return { kind: "aborted" };
@@ -147,7 +169,13 @@ async function stage(context, request, signal, progress) {
147
169
  const section = phase === "apply" ? undefined : phase;
148
170
  if (section !== undefined)
149
171
  await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request.region });
150
- const ran = await runStep(context, { sandbox, phase, ...step }, progress, signal);
172
+ const ran = await runStep(context, {
173
+ sandbox,
174
+ phase,
175
+ label: step.label,
176
+ script: step.script,
177
+ ...(request.secrets === undefined ? {} : { secrets: request.secrets }),
178
+ }, progress, signal);
151
179
  if (ran.kind === "succeeded") {
152
180
  if (section !== undefined)
153
181
  await progress.emit({ kind: "output-ended", section, outcome: "finished" });
@@ -2,6 +2,15 @@
2
2
  export interface RunnerStep {
3
3
  readonly label: string;
4
4
  readonly script: string;
5
+ /**
6
+ * The runner secrets the step gets in its environment, each a name the recipe's `secrets` key declares; none when
7
+ * absent. Each toolchain and prebuild step's names are in the snapshot key, never the values.
8
+ */
9
+ readonly secrets?: readonly string[];
10
+ }
11
+ /** A step as a run uses it: checked, with `secrets` always given, empty when the step names none. */
12
+ export interface ResolvedRunnerStep extends RunnerStep {
13
+ readonly secrets: readonly string[];
5
14
  }
6
15
  /** What a step function may read about the base it is evaluated at. */
7
16
  export interface RunnerStepContext {
@@ -32,8 +41,11 @@ export interface RunnerRecipe {
32
41
  readonly summary?: string;
33
42
  /** Steps run before the base's files are committed in the build sandbox. They must put `git` on `PATH`. */
34
43
  readonly toolchains: RunnerSteps;
35
- /** Steps run after the base's files are committed, such as a frozen install and a full build. */
36
- readonly warm: RunnerSteps;
44
+ /**
45
+ * Steps run after the base's files are committed, such as a frozen install and a full build, saved in the runner
46
+ * snapshot so each run's install and build have little left to do.
47
+ */
48
+ readonly prebuild: RunnerSteps;
37
49
  };
38
50
  readonly run: {
39
51
  /** Installs dependencies on every run. */
@@ -47,6 +59,15 @@ export interface RunnerRecipe {
47
59
  readonly vcpus: number | ((resources: RunnerResources) => number);
48
60
  /** Extra environment variables for the command. It can't set `STORM_RUN`. */
49
61
  readonly env?: Readonly<Record<string, string>>;
62
+ /**
63
+ * The runner secrets: names of environment variables storm reads on this machine as the run starts, before it mints,
64
+ * leases or creates anything. A step gets only the ones its own `secrets` key names, and the command gets none. A
65
+ * run doesn't start unless each is set to one line of 8 or more characters. storm shows each value as `<token>` in
66
+ * what it prints and writes, and writes none itself; a step that gets one must not leave it in the sandbox, where a
67
+ * runner snapshot, later steps and the command could find it. A name can't be one storm sets for a step or for the
68
+ * command, or one that changes how a step's shell or programs run, such as `PATH` or `LD_PRELOAD`.
69
+ */
70
+ readonly secrets?: readonly string[];
50
71
  /** How long the runner sandbox may live, from `10m` to `5h`; `60m` by default. */
51
72
  readonly timeout?: string;
52
73
  /**
@@ -71,8 +92,13 @@ export declare const RECIPE_DEFAULTS: {
71
92
  };
72
93
  /** A recipe that passed `checkRecipe`, with every optional key's default filled in. */
73
94
  export interface CheckedRecipe extends RunnerRecipe {
95
+ readonly run: {
96
+ readonly install: ResolvedRunnerStep;
97
+ readonly build: ResolvedRunnerStep;
98
+ };
74
99
  readonly cwd: string;
75
100
  readonly env: Readonly<Record<string, string>>;
101
+ readonly secrets: readonly string[];
76
102
  readonly timeout: string;
77
103
  /** `timeout` in minutes. */
78
104
  readonly timeoutMinutes: number;
@@ -103,12 +129,13 @@ export type RecipeCheck = {
103
129
  */
104
130
  export declare function checkRecipe(value: unknown): RecipeCheck;
105
131
  /**
106
- * What a recipe's steps are at one base: the list as given, or what the function returns for `context`, checked.
107
- * A function that throws or rejects, or returns anything but a list of steps, is a problem worded to follow the key.
132
+ * What a recipe's steps are at one base: the list as given, or what the function returns for `context`, checked,
133
+ * each with the runner secrets it names, which must be among `declared`, the recipe's `secrets`. A function that
134
+ * throws or rejects, or returns anything but a list of steps, is a problem worded to follow the key.
108
135
  */
109
- export declare function resolveSteps(steps: RunnerSteps, context: RunnerStepContext): Promise<{
136
+ export declare function resolveSteps(steps: RunnerSteps, context: RunnerStepContext, declared: readonly string[]): Promise<{
110
137
  readonly ok: true;
111
- readonly steps: readonly RunnerStep[];
138
+ readonly steps: readonly ResolvedRunnerStep[];
112
139
  } | {
113
140
  readonly ok: false;
114
141
  readonly problem: string;