@cnc-tools/storm 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.js +1 -1
- package/dist/combine-errors.js +2 -2
- package/dist/commands/dashboard.js +1 -1
- package/dist/commands/{run → exec}/cleanup.d.ts +1 -1
- package/dist/commands/{run → exec}/cleanup.js +1 -1
- package/dist/commands/{run/outcomes.d.ts → exec/command.d.ts} +77 -112
- package/dist/commands/exec/command.js +23 -0
- package/dist/commands/{run → exec}/job-summary.d.ts +5 -1
- package/dist/commands/{run → exec}/job-summary.js +5 -2
- package/dist/commands/exec/metadata.d.ts +66 -0
- package/dist/commands/exec/metadata.js +55 -0
- package/dist/commands/{run → exec}/mint-failed.js +4 -4
- package/dist/commands/exec/outcomes.d.ts +614 -0
- package/dist/commands/exec/outcomes.js +338 -0
- package/dist/commands/exec/run-command.d.ts +221 -0
- package/dist/commands/exec/run-command.js +663 -0
- package/dist/commands/exec/run-metadata.d.ts +56 -0
- package/dist/commands/exec/run-metadata.js +58 -0
- package/dist/commands/{run → exec}/run-record.d.ts +27 -1
- package/dist/commands/{run → exec}/run-record.js +8 -0
- package/dist/commands/exec/testserver-flags.d.ts +48 -0
- package/dist/commands/exec/testserver-flags.js +80 -0
- package/dist/commands/runs/facts.js +2 -2
- package/dist/commands/runs/logs/metadata.js +1 -1
- package/dist/commands/runs/logs/outcomes.js +4 -1
- package/dist/commands/runs/past-run.d.ts +2 -2
- package/dist/commands/runs/past-run.js +2 -2
- package/dist/commands/runs/show/metadata.js +2 -2
- package/dist/commands/runs/show/outcomes.js +7 -4
- package/dist/commands/vitest/command.d.ts +299 -0
- package/dist/commands/vitest/command.js +138 -0
- package/dist/commands/vitest/metadata.d.ts +66 -0
- package/dist/commands/vitest/metadata.js +35 -0
- package/dist/commands/vitest/outcomes.d.ts +273 -0
- package/dist/commands/vitest/outcomes.js +77 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/resolve.d.ts +3 -3
- package/dist/config/resolve.js +3 -3
- package/dist/config/resource-config.d.ts +2 -2
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/set.d.ts +15 -4
- package/dist/config/set.js +28 -12
- package/dist/config-file/define.d.ts +8 -6
- package/dist/context.d.ts +6 -3
- package/dist/context.js +4 -2
- package/dist/core/command-provider.d.ts +1 -1
- package/dist/core/presentation.js +1 -1
- package/dist/core/presentations.js +1 -1
- package/dist/resources/testserver/command.d.ts +1 -1
- package/dist/resources/testserver/command.js +1 -1
- package/dist/resources/testserver/config.d.ts +1 -1
- package/dist/resources/testserver/config.js +3 -2
- package/dist/resources/testserver/credential-facts.js +1 -1
- package/dist/resources/testserver/resource.d.ts +2 -2
- package/dist/resources/testserver/sandbox/create.d.ts +2 -2
- package/dist/resources/testserver/sandbox/create.js +2 -2
- package/dist/resources.d.ts +9 -6
- package/dist/resources.js +3 -3
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/payload/payload.d.ts +2 -2
- package/dist/sdk/payload/payload.js +2 -2
- package/dist/vercel-cli/driver.d.ts +1 -1
- package/dist/vercel-cli/entry.d.ts +1 -1
- package/dist/vercel-cli/entry.js +1 -1
- package/dist/vercel-cli/verbose.d.ts +2 -2
- package/dist/vercel-cli/verbose.js +2 -2
- package/dist/vitest/config.d.ts +5 -5
- package/dist/vitest/config.js +5 -5
- package/dist/vitest/find-vitest.d.ts +7 -0
- package/dist/vitest/find-vitest.js +28 -0
- package/dist/vitest/fixtures.d.ts +2 -2
- package/dist/vitest/fixtures.js +3 -3
- package/dist/vitest/gateways.d.ts +37 -6
- package/dist/vitest/gateways.js +3 -2
- package/dist/vitest/live/list-gateway.d.ts +7 -3
- package/dist/vitest/live/list-gateway.js +55 -8
- package/dist/vitest/plan.d.ts +41 -8
- package/dist/vitest/plan.js +47 -16
- package/dist/vitest/sandbox.d.ts +1 -1
- package/dist/vitest/sandbox.js +1 -1
- package/dist/vitest/test-events.d.ts +2 -2
- package/dist/vitest/test-events.js +3 -3
- package/dist/vitest/test-results.d.ts +1 -1
- package/dist/vitest/test-results.js +1 -1
- package/dist/vitest/types.d.ts +1 -1
- package/package.json +2 -2
- package/skills/overview.md +5 -4
- package/skills/read-run-output.md +1 -1
- package/dist/commands/run/command.d.ts +0 -327
- package/dist/commands/run/command.js +0 -620
- package/dist/commands/run/metadata.d.ts +0 -47
- package/dist/commands/run/metadata.js +0 -83
- package/dist/commands/run/outcomes.js +0 -332
- /package/dist/commands/{run → exec}/live-view.d.ts +0 -0
- /package/dist/commands/{run → exec}/live-view.js +0 -0
- /package/dist/commands/{run → exec}/mint-failed.d.ts +0 -0
- /package/dist/commands/{run → exec}/progress.d.ts +0 -0
- /package/dist/commands/{run → exec}/progress.js +0 -0
- /package/dist/commands/{run → exec}/redaction.d.ts +0 -0
- /package/dist/commands/{run → exec}/redaction.js +0 -0
- /package/dist/commands/{run → exec}/run-collector.d.ts +0 -0
- /package/dist/commands/{run → exec}/run-collector.js +0 -0
- /package/dist/commands/{run → exec}/tests-summary.d.ts +0 -0
- /package/dist/commands/{run → exec}/tests-summary.js +0 -0
- /package/dist/commands/{run → exec}/text.d.ts +0 -0
- /package/dist/commands/{run → exec}/text.js +0 -0
- /package/dist/commands/{run → exec}/view.d.ts +0 -0
- /package/dist/commands/{run → exec}/view.js +0 -0
- /package/dist/commands/{run → exec}/waterfall.d.ts +0 -0
- /package/dist/commands/{run → exec}/waterfall.js +0 -0
- /package/dist/commands/{run → exec}/worker-chart.d.ts +0 -0
- /package/dist/commands/{run → exec}/worker-chart.js +0 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { defineErrors, defineOutcomes, renderOutcome } from "@vercel/clinkr";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { RUNNER_STEPS } from "../../core/index.js";
|
|
4
|
+
import { RESOURCE_ERRORS, RESOURCE_PRESENTATIONS, RESOURCE_REPORTS, RUN_CLEANUP } from "../../resources.js";
|
|
5
|
+
import { configErrors } from "../../config/index.js";
|
|
6
|
+
import { credentialErrors } from "../../credential/index.js";
|
|
7
|
+
import { keptText, runnerCleanupWarnings } from "./cleanup.js";
|
|
8
|
+
import { mintFailedErrors } from "./mint-failed.js";
|
|
9
|
+
/** Why the runner couldn't run the command. */
|
|
10
|
+
const runnerFailureSchema = z.union([
|
|
11
|
+
z.object({
|
|
12
|
+
kind: z.enum(["snapshot-build-step-failed", "apply-failed", "install-failed", "build-failed"]),
|
|
13
|
+
/** The step's label. */
|
|
14
|
+
label: z.string(),
|
|
15
|
+
/** Its exit code; null when it ended without one. */
|
|
16
|
+
exitCode: z.number().nullable(),
|
|
17
|
+
/** Its last 40 output lines. */
|
|
18
|
+
tail: z.array(z.string()),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
kind: z.literal("sandbox-api-failed"),
|
|
22
|
+
/** The Sandbox call that failed. */
|
|
23
|
+
operation: z.string(),
|
|
24
|
+
/** The HTTP status the Sandbox API answered; null when it answered none. */
|
|
25
|
+
status: z.number().nullable(),
|
|
26
|
+
message: z.string(),
|
|
27
|
+
}),
|
|
28
|
+
z.object({
|
|
29
|
+
kind: z.literal("checkout-failed"),
|
|
30
|
+
/** What git or tar said. */
|
|
31
|
+
message: z.string(),
|
|
32
|
+
/** The failed command; null when there was none. */
|
|
33
|
+
command: z.string().nullable(),
|
|
34
|
+
}),
|
|
35
|
+
z.object({ kind: z.literal("credential-claims-missing"), team: z.string(), project: z.string() }),
|
|
36
|
+
]);
|
|
37
|
+
/** How a step ended, as a message says it. */
|
|
38
|
+
function stepEnded(exitCode) {
|
|
39
|
+
return exitCode === null ? "ended without an exit code" : `exited ${exitCode}`;
|
|
40
|
+
}
|
|
41
|
+
/** The headline and the next step for a runner failure. */
|
|
42
|
+
function runnerFailureText(failure) {
|
|
43
|
+
switch (failure.kind) {
|
|
44
|
+
case "snapshot-build-step-failed":
|
|
45
|
+
return {
|
|
46
|
+
message: `The runner snapshot build's step "${failure.label}" ${stepEnded(failure.exitCode)}. The command didn't run.`,
|
|
47
|
+
next: "Fix the step in the runner recipe, then retry. A failed build records no runner snapshot.",
|
|
48
|
+
};
|
|
49
|
+
case "apply-failed":
|
|
50
|
+
return {
|
|
51
|
+
message: `Couldn't apply your changes in the runner sandbox: "${failure.label}" ${stepEnded(failure.exitCode)}. The command didn't run.`,
|
|
52
|
+
next: "Check the output for the file that didn't apply, then retry.",
|
|
53
|
+
};
|
|
54
|
+
case "install-failed":
|
|
55
|
+
return {
|
|
56
|
+
message: `The runner's install, "${failure.label}", ${stepEnded(failure.exitCode)}. The command didn't run.`,
|
|
57
|
+
next: "Fix run.install in the runner recipe, or what it installs, then retry.",
|
|
58
|
+
};
|
|
59
|
+
case "build-failed":
|
|
60
|
+
return {
|
|
61
|
+
message: `The runner's build, "${failure.label}", ${stepEnded(failure.exitCode)}. The command didn't run.`,
|
|
62
|
+
next: "Fix the build, or run.build in the runner recipe, then retry.",
|
|
63
|
+
};
|
|
64
|
+
case "sandbox-api-failed":
|
|
65
|
+
return {
|
|
66
|
+
message: `A Vercel Sandbox call failed (${failure.operation}${failure.status === null ? "" : `, HTTP ${failure.status}`}): ${failure.message}. ${failure.operation === "run-command" ? "The command's outcome is unknown." : "The command didn't run."}`,
|
|
67
|
+
next: "Retry; if it keeps failing, check the Vercel Sandbox status and the project's Sandbox access.",
|
|
68
|
+
};
|
|
69
|
+
case "checkout-failed":
|
|
70
|
+
return {
|
|
71
|
+
message: `git or tar failed on this machine: ${failure.message}. The command didn't run.`,
|
|
72
|
+
next: "Fix the checkout, then retry.",
|
|
73
|
+
};
|
|
74
|
+
case "credential-claims-missing":
|
|
75
|
+
return {
|
|
76
|
+
message: `The credential minted for project ${failure.project} on team ${failure.team} names no team and project ids (its owner_id and project_id claims), so the runner sandbox can't use it. The command didn't run.`,
|
|
77
|
+
next: "Mint for a Vercel project whose development OIDC tokens carry owner_id and project_id, then retry.",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** The timeline's rows, in order: the mint, each resource lane in provider order, the runner, the tests, the cleanup. */
|
|
82
|
+
const ROW_NAMES = [
|
|
83
|
+
"mint",
|
|
84
|
+
...RESOURCE_PRESENTATIONS.lanes.map(({ lane }) => lane),
|
|
85
|
+
"runner",
|
|
86
|
+
"tests",
|
|
87
|
+
"cleanup",
|
|
88
|
+
];
|
|
89
|
+
/** The timeline's steps: each resource lane's, in provider order, then the runner's. */
|
|
90
|
+
const STEP_NAMES = [...RESOURCE_PRESENTATIONS.lanes.flatMap(({ steps }) => steps), ...RUNNER_STEPS];
|
|
91
|
+
/** How a lane or step ended in the timeline: still going when the run ended is `unfinished`. */
|
|
92
|
+
const timelineOutcomeSchema = z.enum(["done", "failed", "stopped", "unfinished"]);
|
|
93
|
+
/** A run's waterfall (`Timeline`), times in milliseconds since the run started, as `timeline.json` holds it too. */
|
|
94
|
+
export const timelineSchema = z.object({
|
|
95
|
+
/** When the run started, as an ISO time. */
|
|
96
|
+
startedAt: z.string(),
|
|
97
|
+
/** From the run's start to its last event. */
|
|
98
|
+
totalMs: z.number(),
|
|
99
|
+
/** The lanes in order: mint, each resource's lane, runner, tests, cleanup; each only when the run got that far. */
|
|
100
|
+
rows: z.array(z.object({
|
|
101
|
+
name: z.enum(ROW_NAMES),
|
|
102
|
+
startMs: z.number(),
|
|
103
|
+
endMs: z.number(),
|
|
104
|
+
outcome: timelineOutcomeSchema,
|
|
105
|
+
/** The lane's steps: a resource lane's, such as the Testserver side's lease and create, and the runner's snapshot, start, upload, apply, install and build. */
|
|
106
|
+
steps: z.array(z.object({
|
|
107
|
+
name: z.enum(STEP_NAMES),
|
|
108
|
+
startMs: z.number(),
|
|
109
|
+
endMs: z.number(),
|
|
110
|
+
outcome: timelineOutcomeSchema,
|
|
111
|
+
})),
|
|
112
|
+
/** How long the lane, once ready, waited for the other before the command started. */
|
|
113
|
+
idleMs: z.number(),
|
|
114
|
+
/** The runner lane's: whether it reused or built its runner snapshot. */
|
|
115
|
+
snapshot: z.enum(["reused", "built"]).optional(),
|
|
116
|
+
/** A resource lane's that counts them, such as the Testserver lane's: how many it reused and created. */
|
|
117
|
+
sandboxes: z.object({ reused: z.number(), created: z.number() }).optional(),
|
|
118
|
+
})),
|
|
119
|
+
/** The lanes the command waited on, then the command; empty when the command didn't start. */
|
|
120
|
+
criticalPath: z.array(z.enum(ROW_NAMES)),
|
|
121
|
+
});
|
|
122
|
+
/** What a `ran` outcome says of a run whose command ran and ended. No field carries the credential. */
|
|
123
|
+
export const ranSchema = z.object({
|
|
124
|
+
/** storm's version. */
|
|
125
|
+
version: z.string(),
|
|
126
|
+
/** The git commit storm was built from, as its version line shows it (`3f2a9c1b7d4e`, `-dirty` appended when built from a tree with uncommitted changes); null when unknown. */
|
|
127
|
+
commit: z.string().nullable(),
|
|
128
|
+
/** The config file the run's settings came from (its absolute path); null when none applied. */
|
|
129
|
+
configFile: z.string().nullable(),
|
|
130
|
+
/** What each acquired resource that reports something says of itself, keyed by resource name, such as the Testserver pool's sandboxes and build. */
|
|
131
|
+
resources: RESOURCE_REPORTS.ranSchema,
|
|
132
|
+
/** What the run's cleanup left: in a runner run, the runner sandbox it kept running and the runner's sandboxes it couldn't stop or delete (`runner`, null otherwise), and what releasing each resource it held couldn't do, keyed by resource name (`resources`, `{}` when it held none). */
|
|
133
|
+
cleanup: RUN_CLEANUP.schema,
|
|
134
|
+
/** How the command ended: its exit code, or the signal that ended it; both null for a remote command that ended without an exit code. */
|
|
135
|
+
command: z.object({ exitCode: z.number().nullable(), signal: z.string().nullable() }),
|
|
136
|
+
/** In a runner run, the runner sandbox the command ran in; null otherwise. */
|
|
137
|
+
runner: z
|
|
138
|
+
.object({
|
|
139
|
+
/** The runner snapshot it started from. */
|
|
140
|
+
snapshotId: z.string(),
|
|
141
|
+
/** The runner snapshot's base, a full SHA. */
|
|
142
|
+
base: z.string(),
|
|
143
|
+
/** Whether this run built the runner snapshot. */
|
|
144
|
+
built: z.boolean(),
|
|
145
|
+
vcpus: z.number(),
|
|
146
|
+
region: z.string(),
|
|
147
|
+
runtime: z.string(),
|
|
148
|
+
})
|
|
149
|
+
.nullable(),
|
|
150
|
+
/** The run's waterfall, as the run directory's timeline.json holds it: each lane's span and steps in milliseconds since the run started, how they ended, idle time, and the critical path. */
|
|
151
|
+
timeline: timelineSchema,
|
|
152
|
+
/** The run's run directory's run id, which `storm runs show` takes; null when the run couldn't make one. */
|
|
153
|
+
runId: z.string().nullable(),
|
|
154
|
+
});
|
|
155
|
+
/** What a `ran` outcome is, for its description. */
|
|
156
|
+
export const RAN_DESCRIPTION = "The command ran and ended. storm exits with its code, or 128 + n when signal n ended it, whatever this result's exit code.";
|
|
157
|
+
/** How a `ran` outcome renders: its warnings, and the runner sandbox the run kept running, if any. */
|
|
158
|
+
export function renderRan(ran) {
|
|
159
|
+
const warnings = [
|
|
160
|
+
...RESOURCE_REPORTS.ranWarnings(ran.resources),
|
|
161
|
+
...(ran.runner !== null && ran.command.exitCode === null && ran.command.signal === null
|
|
162
|
+
? [
|
|
163
|
+
{
|
|
164
|
+
reason: "remote_no_exit_code",
|
|
165
|
+
message: "The command ended in the runner sandbox without an exit code, so storm exits 1.",
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
: []),
|
|
169
|
+
...runnerCleanupWarnings(ran.cleanup.runner),
|
|
170
|
+
...RESOURCE_REPORTS.cleanupWarnings(ran.cleanup.resources),
|
|
171
|
+
];
|
|
172
|
+
// The waterfall, which the run prints on stderr before this, is the human summary; the kept runner sandbox
|
|
173
|
+
// follows it, so a person sees where to connect last.
|
|
174
|
+
const kept = ran.cleanup.runner?.kept ?? null;
|
|
175
|
+
return renderOutcome({
|
|
176
|
+
...(kept === null ? {} : { message: keptText(kept) }),
|
|
177
|
+
...(warnings.length === 0 ? {} : { warnings }),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** The errors only a run ends with, beside the config's, the credential's, the resources' and the mint's. */
|
|
181
|
+
export const runErrors = defineErrors({
|
|
182
|
+
credentialUnused: {
|
|
183
|
+
exitCode: 2,
|
|
184
|
+
description: "--credential was given to a run that holds no resource that takes a credential.",
|
|
185
|
+
schema: z.object({
|
|
186
|
+
/** The flags given that no held resource takes, as typed, such as --credential. */
|
|
187
|
+
flags: z.array(z.string()),
|
|
188
|
+
/** The config file that applied; null when none did. */
|
|
189
|
+
configFile: z.string().nullable(),
|
|
190
|
+
}),
|
|
191
|
+
render: ({ flags }) => ({
|
|
192
|
+
message: `${flags.join(", ")} ${flags.length === 1 ? "applies" : "apply"} only to a run holding a resource that takes a credential, and this run holds none.`,
|
|
193
|
+
next: [
|
|
194
|
+
{
|
|
195
|
+
type: "text",
|
|
196
|
+
text: `Drop ${flags.join(" and ")}, or give the run a resource that takes a credential, in storm.config.ts or on the command line.`,
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
}),
|
|
200
|
+
},
|
|
201
|
+
missingRunner: {
|
|
202
|
+
exitCode: 2,
|
|
203
|
+
description: "A runner run (no --local) needs a runner recipe, and no storm.config.ts gives a runner key.",
|
|
204
|
+
schema: z.object({
|
|
205
|
+
/** The config file that applied; null when none did. */
|
|
206
|
+
configFile: z.string().nullable(),
|
|
207
|
+
}),
|
|
208
|
+
render: ({ configFile }) => ({
|
|
209
|
+
message: configFile === null
|
|
210
|
+
? "A runner run needs a runner recipe, and no storm.config.ts applies."
|
|
211
|
+
: `A runner run needs a runner recipe, and ${configFile} has no runner key.`,
|
|
212
|
+
next: [
|
|
213
|
+
{
|
|
214
|
+
type: "text",
|
|
215
|
+
text: "Add a runner recipe under the runner key of storm.config.ts, or run on this machine with --local.",
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
noBaseRef: {
|
|
221
|
+
exitCode: 1,
|
|
222
|
+
description: "In a runner run, none of the runner recipe's baseRefs exists locally and shares history with HEAD, so there is no base. storm never fetches.",
|
|
223
|
+
schema: z.object({
|
|
224
|
+
/** Each ref in baseRefs, and why it gave no base. */
|
|
225
|
+
refs: z.array(z.object({ ref: z.string(), reason: z.enum(["missing", "unrelated"]) })),
|
|
226
|
+
}),
|
|
227
|
+
render: ({ refs }) => ({
|
|
228
|
+
message: `No base for the runner: none of ${refs.map(({ ref }) => ref).join(", ")} exists locally and shares history with HEAD. The command didn't run.`,
|
|
229
|
+
rows: [
|
|
230
|
+
[
|
|
231
|
+
"Base refs",
|
|
232
|
+
refs.map(({ ref, reason }) => reason === "missing" ? `${ref}: no such local ref` : `${ref}: shares no history with HEAD`),
|
|
233
|
+
],
|
|
234
|
+
],
|
|
235
|
+
next: [
|
|
236
|
+
{
|
|
237
|
+
type: "text",
|
|
238
|
+
text: refs.some(({ ref }) => ref === "main" || ref === "origin/main")
|
|
239
|
+
? "Run git fetch origin main, then retry."
|
|
240
|
+
: `Fetch or create one of ${refs.map(({ ref }) => ref).join(", ")}, then retry.`,
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
},
|
|
245
|
+
submodulesRefused: {
|
|
246
|
+
exitCode: 1,
|
|
247
|
+
description: "In a runner run, the checkout has Git submodules, which neither the upload nor the base's files carry.",
|
|
248
|
+
schema: z.object({ paths: z.array(z.string()) }),
|
|
249
|
+
render: ({ paths }) => ({
|
|
250
|
+
message: `The checkout has Git submodules, which the runner can't carry: ${paths.join(", ")}. The command didn't run.`,
|
|
251
|
+
next: [{ type: "text", text: "Run on this machine with --local." }],
|
|
252
|
+
}),
|
|
253
|
+
},
|
|
254
|
+
snapshotGone: {
|
|
255
|
+
exitCode: 1,
|
|
256
|
+
description: "In a runner run, the cached runner snapshot the run picked was gone (the Sandbox API answered 410), so its cache entry was removed and the command didn't run. The next run picks another runner snapshot or builds one.",
|
|
257
|
+
schema: z.object({
|
|
258
|
+
snapshotId: z.string(),
|
|
259
|
+
/** The runner snapshot's base, a full SHA. */
|
|
260
|
+
base: z.string(),
|
|
261
|
+
/** Why its cache entry couldn't be removed; null when it was. */
|
|
262
|
+
removal: z.object({ path: z.string(), message: z.string() }).nullable(),
|
|
263
|
+
/** What the run couldn't clean up. */
|
|
264
|
+
cleanup: RUN_CLEANUP.schema,
|
|
265
|
+
}),
|
|
266
|
+
render: ({ snapshotId, removal, cleanup }) => {
|
|
267
|
+
const rows = RUN_CLEANUP.rows(cleanup);
|
|
268
|
+
return {
|
|
269
|
+
message: `Runner snapshot ${snapshotId} is gone, before its cache entry said it expires. ${removal === null ? "Removed its cache entry." : `Couldn't remove its cache entry at ${removal.path}: ${removal.message}.`} The command didn't run.`,
|
|
270
|
+
...(rows.length === 0 ? {} : { rows }),
|
|
271
|
+
next: [
|
|
272
|
+
{
|
|
273
|
+
type: "text",
|
|
274
|
+
text: removal === null
|
|
275
|
+
? "Run again: the next run picks another runner snapshot or builds one."
|
|
276
|
+
: `Remove ${removal.path}, then run again.`,
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
runnerFailed: {
|
|
283
|
+
exitCode: 1,
|
|
284
|
+
description: "In a runner run, the runner couldn't run the command: a snapshot build step, applying the changes, the install or the build failed (with the step's last 40 output lines), a Vercel Sandbox call failed, git or tar failed on this machine, or the credential names no team and project ids.",
|
|
285
|
+
schema: z.object({
|
|
286
|
+
failure: runnerFailureSchema,
|
|
287
|
+
/** What the run couldn't clean up; its `runner` is null when the run failed before it started a sandbox. */
|
|
288
|
+
cleanup: RUN_CLEANUP.schema,
|
|
289
|
+
}),
|
|
290
|
+
render: ({ failure, cleanup }) => {
|
|
291
|
+
const { message, next } = runnerFailureText(failure);
|
|
292
|
+
const rows = [
|
|
293
|
+
...("tail" in failure && failure.tail.length > 0 ? [["Last output", failure.tail]] : []),
|
|
294
|
+
...(failure.kind === "checkout-failed" && failure.command !== null
|
|
295
|
+
? [["Command", failure.command]]
|
|
296
|
+
: []),
|
|
297
|
+
...RUN_CLEANUP.rows(cleanup),
|
|
298
|
+
];
|
|
299
|
+
return { message, ...(rows.length === 0 ? {} : { rows }), next: [{ type: "text", text: next }] };
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
spawnFailed: {
|
|
303
|
+
exitCode: 1,
|
|
304
|
+
description: "The command couldn't start.",
|
|
305
|
+
schema: z.object({
|
|
306
|
+
/** The command's first argument: what storm tried to run. */
|
|
307
|
+
executable: z.string(),
|
|
308
|
+
/** What the OS said. */
|
|
309
|
+
message: z.string(),
|
|
310
|
+
/** What the run couldn't clean up; its `runner` is null, since only a local run spawns its command here. */
|
|
311
|
+
cleanup: RUN_CLEANUP.schema,
|
|
312
|
+
}),
|
|
313
|
+
render: ({ executable, message, cleanup }) => {
|
|
314
|
+
const rows = RUN_CLEANUP.rows(cleanup);
|
|
315
|
+
return {
|
|
316
|
+
message: `Couldn't start the command ${executable}: ${message}`,
|
|
317
|
+
...(rows.length === 0 ? {} : { rows }),
|
|
318
|
+
next: [
|
|
319
|
+
{ type: "text", text: "Check the command after --; it runs with no shell, as the argument list given." },
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
/** Every error a run ends with, in order: the config's, the credential's, each resource's, the mint's, the run's. */
|
|
326
|
+
export const RUN_ERRORS = {
|
|
327
|
+
...configErrors,
|
|
328
|
+
...credentialErrors,
|
|
329
|
+
// Every resource's errors, in provider order.
|
|
330
|
+
...RESOURCE_ERRORS,
|
|
331
|
+
...mintFailedErrors,
|
|
332
|
+
...runErrors,
|
|
333
|
+
};
|
|
334
|
+
/** How `exec` ends. No outcome carries the credential. */
|
|
335
|
+
export const outcomes = defineOutcomes({
|
|
336
|
+
results: { ran: { schema: ranSchema, description: RAN_DESCRIPTION, render: renderRan } },
|
|
337
|
+
errors: RUN_ERRORS,
|
|
338
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { type ArgumentIssue, type CommandError, type CommandResult, type ExecutionContext } from "@vercel/clinkr";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { StormApp } from "../../context.ts";
|
|
4
|
+
import { type CredentialSourceChoice, type MintTarget } from "../../credential/index.ts";
|
|
5
|
+
import { type CheckedRecipe, type CheckoutFailure } from "../../runner/index.ts";
|
|
6
|
+
import { type StormSetValues } from "../../resources.ts";
|
|
7
|
+
import { type ranSchema } from "./outcomes.ts";
|
|
8
|
+
import { type RunRecordPlan } from "./run-record.ts";
|
|
9
|
+
/** The request fields every run takes, `exec`'s and `vitest`'s: each command adds the fields for its command. */
|
|
10
|
+
export declare const RUN_REQUEST_FIELDS: {
|
|
11
|
+
set: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
testserverSandboxes: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
testserverBuild: z.ZodOptional<z.ZodString>;
|
|
14
|
+
testserverMinTimeLeft: z.ZodOptional<z.ZodString>;
|
|
15
|
+
testserverTtl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
testserverNoCreate: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
18
|
+
project: z.ZodOptional<z.ZodString>;
|
|
19
|
+
credential: z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
"github-actions": "github-actions";
|
|
21
|
+
mint: "mint";
|
|
22
|
+
}>>;
|
|
23
|
+
local: z.ZodDefault<z.ZodBoolean>;
|
|
24
|
+
rebuildSnapshot: z.ZodDefault<z.ZodBoolean>;
|
|
25
|
+
showOutput: z.ZodDefault<z.ZodBoolean>;
|
|
26
|
+
keepSandbox: z.ZodOptional<z.ZodString>;
|
|
27
|
+
verbose: z.ZodDefault<z.ZodBoolean>;
|
|
28
|
+
};
|
|
29
|
+
/** The CLI spellings of the fields every run takes. */
|
|
30
|
+
export declare const RUN_CLI_OPTIONS: {
|
|
31
|
+
readonly project: {
|
|
32
|
+
readonly short: "p";
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
declare const runRequestSchema: z.ZodObject<{
|
|
36
|
+
set: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
37
|
+
testserverSandboxes: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
testserverBuild: z.ZodOptional<z.ZodString>;
|
|
39
|
+
testserverMinTimeLeft: z.ZodOptional<z.ZodString>;
|
|
40
|
+
testserverTtl: z.ZodOptional<z.ZodString>;
|
|
41
|
+
testserverNoCreate: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
43
|
+
project: z.ZodOptional<z.ZodString>;
|
|
44
|
+
credential: z.ZodOptional<z.ZodEnum<{
|
|
45
|
+
"github-actions": "github-actions";
|
|
46
|
+
mint: "mint";
|
|
47
|
+
}>>;
|
|
48
|
+
local: z.ZodDefault<z.ZodBoolean>;
|
|
49
|
+
rebuildSnapshot: z.ZodDefault<z.ZodBoolean>;
|
|
50
|
+
showOutput: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
keepSandbox: z.ZodOptional<z.ZodString>;
|
|
52
|
+
verbose: z.ZodDefault<z.ZodBoolean>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
/** What every run's request holds. */
|
|
55
|
+
export type RunCommandRequest = z.output<typeof runRequestSchema>;
|
|
56
|
+
/** A run settled before it starts: its config file, its resources' options and requests, and where it runs. */
|
|
57
|
+
export type SettledRun = Extract<Awaited<ReturnType<typeof settleRun>>, {
|
|
58
|
+
readonly ok: true;
|
|
59
|
+
}>;
|
|
60
|
+
/** What a `ran` outcome reports of every run, which a command's own `ran` may extend. */
|
|
61
|
+
export type RanFacts = z.input<typeof ranSchema>;
|
|
62
|
+
/**
|
|
63
|
+
* The command a settled run runs: its argv, the settled run it runs with, which `prepare` may have changed (such as
|
|
64
|
+
* its Testserver sandbox count) but not its secrets, which the run hides from the settled run it gave `prepare`, and
|
|
65
|
+
* its test plan, which `run.json` records when there is one.
|
|
66
|
+
*/
|
|
67
|
+
export interface PreparedCommand<TPlan> {
|
|
68
|
+
readonly ok: true;
|
|
69
|
+
readonly argv: readonly string[];
|
|
70
|
+
readonly settled: SettledRun;
|
|
71
|
+
readonly plan: TPlan;
|
|
72
|
+
}
|
|
73
|
+
/** How one command runs: its name, the command its settled run runs, and its `ran` outcome. */
|
|
74
|
+
export interface RunCommandSpec<TPlan, TRan, TRefusal> {
|
|
75
|
+
/** The invoking command's name, `exec` or `vitest`, which the job summary's heading names. */
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/**
|
|
78
|
+
* The command to run once the run is settled, before anything is minted, leased or started and before a runner
|
|
79
|
+
* run's local checks; or a refusal, which ends the run there, with the run's secrets hidden. Once `signal`, the
|
|
80
|
+
* invocation's, aborts, it stops what it started as soon as it can; the run then cancels, whatever it answers.
|
|
81
|
+
*/
|
|
82
|
+
prepare(settled: SettledRun, signal: AbortSignal): Promise<PreparedCommand<TPlan> | {
|
|
83
|
+
readonly ok: false;
|
|
84
|
+
readonly refusal: TRefusal;
|
|
85
|
+
}>;
|
|
86
|
+
/** The `ran` outcome for a run whose command ran, from what every run reports and the command's plan. */
|
|
87
|
+
ran(facts: RanFacts, plan: TPlan): TRan;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Runs a run's command, the argv `spec.prepare` gives once the run is settled (`exec`'s command after `--`, or the
|
|
91
|
+
* `vitest run` argv `vitest` builds), with the run payload in `STORM_RUN` and the host variables each resource
|
|
92
|
+
* names removed (`TESTSERVER_BASES`/`TESTSERVER_BASE` for the Testserver pool), waits for it, and prints a waterfall.
|
|
93
|
+
* With a Testserver side it first leases usable Testserver sandboxes from the pool, creates the rest, and prints the
|
|
94
|
+
* sandbox list, and releases the leases once the command ends. The process exits with the command's code, or `128 + n`
|
|
95
|
+
* when signal `n` ended it: `bin/storm.ts` applies the status this records in `app.exit`, which Clinkr's 0 or 1
|
|
96
|
+
* can't carry.
|
|
97
|
+
*
|
|
98
|
+
* A run holds a resource when `storm.config.ts` has it under `resources` or the command line gives one of its
|
|
99
|
+
* options: a `--set resources.<name>.<option>=<value>`, or for the Testserver pool resource one of its own flags
|
|
100
|
+
* (`--testserver-sandboxes`, `--testserver-build`, `--testserver-min-time-left`, `--testserver-ttl`,
|
|
101
|
+
* `--testserver-no-create`; `testserver-flags.ts`). A run has a Testserver side when it holds the Testserver pool
|
|
102
|
+
* resource; without one, the run payload names no Testserver sandbox.
|
|
103
|
+
*
|
|
104
|
+
* Signals: before the command starts, the first signal stops the run at its next step, lets creates in flight settle,
|
|
105
|
+
* releases its leases, and cancels (exit `128 + n`). A signal while `spec.prepare` runs, such as while `vitest` counts
|
|
106
|
+
* the tests, stops it and cancels the run before anything is minted, leased or started (`canceledBeforeStart`). While
|
|
107
|
+
* the command runs, Ctrl+C and a closed terminal reach it directly through its process group, so only SIGTERM is
|
|
108
|
+
* passed on; either way the run waits for the command. A second signal makes Clinkr's host exit at once with
|
|
109
|
+
* `128 + n`, leaving the leases for the next run to reclaim, since their holder is gone.
|
|
110
|
+
*
|
|
111
|
+
* `scope` and `project` come from `--scope` and `--project`, else `storm.config.ts` (found from the working
|
|
112
|
+
* directory and checked whole); they have no default, so one of the two must give them when the run mints. Each
|
|
113
|
+
* resource's options come from the command line, else the file's section, else the option's default (the registry's
|
|
114
|
+
* resource configs, `src/resources.ts`). On the command line, each Testserver pool option has its own
|
|
115
|
+
* `--testserver-<option>` flag, and any other option comes from `--set resources.<name>.<option>=<value>`, which may
|
|
116
|
+
* repeat. An unknown key path, a key path given twice, a key path with its own flag, or a value its option's rule
|
|
117
|
+
* refuses is a usage error. Options that don't fit together once merged, such as a TTL not longer than `minTimeLeft`,
|
|
118
|
+
* or a `--testserver-ttl` with `noCreate`, are `invalid_resource_options`, which names each value's source.
|
|
119
|
+
*
|
|
120
|
+
* By default the command runs in a runner sandbox, from the `runner` recipe of `storm.config.ts`, which only a
|
|
121
|
+
* runner run reads: `missing_runner` without one. `--local` (no config key) runs it on this machine instead. The
|
|
122
|
+
* runner's local checks (`prepareRunner`) run before anything is minted, leased or created. A runner run always mints,
|
|
123
|
+
* for the runner sandbox, so it needs `scope` and `project` whatever resources it holds. In a runner run, the first
|
|
124
|
+
* SIGINT, SIGTERM or SIGHUP stops the run in any phase: the remote command is killed, every sandbox the run started is
|
|
125
|
+
* stopped and deleted, the leases are released, and the run cancels. `--rebuild-snapshot` (no config key, not with
|
|
126
|
+
* `--local`) builds a runner snapshot whatever the cache holds.
|
|
127
|
+
*
|
|
128
|
+
* `--credential` (no config key) picks the credential source: `mint`, the default, or `github-actions`, which requests
|
|
129
|
+
* a GitHub Actions OIDC token instead and so needs no `--scope` or `--project`; any given are unused. A runner run
|
|
130
|
+
* needs the mint, so `--credential github-actions` without `--local` is a usage error. The registry says whether a held
|
|
131
|
+
* resource takes the credential (`RESOURCE_COMMANDS.takesCredential`): the Testserver pool does unless `noCreate`. A
|
|
132
|
+
* `--credential` given to a run where none does is `credential_unused`.
|
|
133
|
+
*
|
|
134
|
+
* Progress shows by the app's presentation (`presentation.ts`): a live view on a terminal a person watches, plain lines
|
|
135
|
+
* elsewhere, folded for GitHub Actions, nothing under `--json`. `--show-output` (no config key, not with `--local`)
|
|
136
|
+
* prints the runner's step output above the live view. `--verbose` (no config key) prints each create's progress
|
|
137
|
+
* messages and the runner's step output, and sets `verbose` in the run payload. Every run, `--json` included, writes a
|
|
138
|
+
* run directory (`core/run-directory.ts`), and a run that can't make one goes on without it; the waterfall names it and
|
|
139
|
+
* the `storm runs show` command that reads the run back by its run id, which a ran outcome carries as `runId`, and
|
|
140
|
+
* in a GitHub Actions step with a job summary the run appends a Markdown summary there.
|
|
141
|
+
*
|
|
142
|
+
* Each resource is a provider (the registry, `src/resources.ts`, lists them), whose folder under `src/resources/` says
|
|
143
|
+
* what the run does with it, and whose command half settles it (`RESOURCE_COMMANDS.settle`). The run refuses in this
|
|
144
|
+
* order: `invalid_config`, `invalid_resource_options`, `credential_unused`; in a runner run `missing_runner`, then
|
|
145
|
+
* `missing_target`; in a local run where a resource takes the credential, `missing_target` for the mint; then each
|
|
146
|
+
* resource's settle, in provider order; then `spec.prepare`'s refusal, if any. A resource's secrets, such as a token,
|
|
147
|
+
* are hidden as `<token>` in the run's progress, its run directory, its job summary, its outcome, `spec.prepare`'s
|
|
148
|
+
* refusal, and its command's output, in either kind of run.
|
|
149
|
+
*/
|
|
150
|
+
export declare function runCommand<TPlan extends RunRecordPlan | undefined, TRan extends CommandResult, TRefusal extends CommandError = never>({ app, ui, signal }: ExecutionContext<StormApp>, request: RunCommandRequest, spec: RunCommandSpec<TPlan, TRan, TRefusal>): Promise<TRan | TRefusal | import("@vercel/clinkr").ClinkrError<"canceled"> | CommandError<"credential_unused"> | CommandError<"invalid_config"> | CommandError<"invalid_resource_options"> | CommandError<"mint_failed"> | CommandError<"missing_runner"> | CommandError<"missing_target"> | CommandError<"no_base_ref"> | CommandError<"runner_failed"> | CommandError<"snapshot_gone"> | CommandError<"spawn_failed"> | CommandError<"submodules_refused"> | CommandError<"credential_rejected" | "github_fixture_repo_unavailable" | "github_token_missing" | "no_sandboxes" | "no_usable_sandboxes" | "pool_unavailable" | "pool_unreadable" | "token_request_failed">>;
|
|
151
|
+
/** What is wrong with a run's request that its schema can't say, as `validate` reports it. */
|
|
152
|
+
export declare function runProblems({ set, credential, local, rebuildSnapshot, showOutput, keepSandbox, ...rest }: RunCommandRequest): readonly ArgumentIssue[];
|
|
153
|
+
/**
|
|
154
|
+
* A run canceled before it started, while it was settled or prepared: nothing was minted, leased or started, and the
|
|
155
|
+
* command didn't run.
|
|
156
|
+
*/
|
|
157
|
+
export declare function canceledBeforeStart(): import("@vercel/clinkr").ClinkrError<"canceled">;
|
|
158
|
+
/**
|
|
159
|
+
* The refusal for a runner run whose checkout git couldn't read before anything was minted, leased or started:
|
|
160
|
+
* `runner_failed` with `checkout-failed`, holding nothing.
|
|
161
|
+
*/
|
|
162
|
+
export declare function checkoutFailedRefusal(failure: CheckoutFailure): CommandError<"runner_failed">;
|
|
163
|
+
/** How long a runner sandbox keeps running once its run ends, when neither the flag nor the recipe says. */
|
|
164
|
+
export declare const DEFAULT_KEEP_SANDBOX_MINUTES = 30;
|
|
165
|
+
/**
|
|
166
|
+
* Where a settled run runs: with `--local` on this machine, with the credential source it settled when a held
|
|
167
|
+
* resource takes one; or by default in a runner sandbox, with the runner recipe and the team and project the runner
|
|
168
|
+
* sandbox's credential is minted for, whose one mint the resources share.
|
|
169
|
+
*/
|
|
170
|
+
type RunWhere = {
|
|
171
|
+
readonly kind: "local";
|
|
172
|
+
readonly credential: CredentialSourceChoice | undefined;
|
|
173
|
+
} | {
|
|
174
|
+
readonly kind: "runner";
|
|
175
|
+
readonly recipe: CheckedRecipe;
|
|
176
|
+
readonly target: MintTarget;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Settles a run before it starts, refusing in this order: the config file (`invalid_config`); each held resource's
|
|
180
|
+
* merged options (`invalid_resource_options`); a `--credential` no held resource takes (`credential_unused`); in a
|
|
181
|
+
* runner run, the runner recipe (`missing_runner`) and the team and project its mint needs (`missing_target`); in a
|
|
182
|
+
* local run where a held resource takes the credential, the credential source (`missing_target` for the mint); then
|
|
183
|
+
* each held resource's own settle, in provider order.
|
|
184
|
+
*/
|
|
185
|
+
declare function settleRun(app: StormApp, request: {
|
|
186
|
+
readonly given: StormSetValues;
|
|
187
|
+
readonly scope?: string | undefined;
|
|
188
|
+
readonly project?: string | undefined;
|
|
189
|
+
readonly local: boolean;
|
|
190
|
+
readonly credential?: CredentialSourceChoice["source"] | undefined;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
readonly ok: false;
|
|
193
|
+
readonly refusal: CommandError<"invalid_config">;
|
|
194
|
+
} | {
|
|
195
|
+
readonly ok: false;
|
|
196
|
+
readonly refusal: CommandError<"invalid_resource_options">;
|
|
197
|
+
} | {
|
|
198
|
+
readonly ok: false;
|
|
199
|
+
readonly refusal: CommandError<"missing_target">;
|
|
200
|
+
} | {
|
|
201
|
+
readonly ok: false;
|
|
202
|
+
readonly refusal: CommandError<"credential_rejected" | "github_fixture_repo_unavailable" | "github_token_missing" | "no_sandboxes" | "no_usable_sandboxes" | "pool_unavailable" | "pool_unreadable" | "token_request_failed">;
|
|
203
|
+
} | {
|
|
204
|
+
readonly ok: false;
|
|
205
|
+
readonly refusal: CommandError<"credential_unused">;
|
|
206
|
+
} | {
|
|
207
|
+
readonly ok: false;
|
|
208
|
+
readonly refusal: CommandError<"missing_runner">;
|
|
209
|
+
} | {
|
|
210
|
+
readonly ok: true;
|
|
211
|
+
readonly configFile: string | null;
|
|
212
|
+
readonly file: {
|
|
213
|
+
readonly ok: true;
|
|
214
|
+
} & import("../../config/settings-file.ts").SettingsFile<(import("../../config/resource-config.ts").ResourceConfig<"githubFixtureRepo", import("../../resources/github/resource.ts").GitHubFixtureRepoOptions, import("../../resources/github/config.ts").GitHubFixtureRepoSettings, keyof import("../../resources/github/resource.ts").GitHubFixtureRepoOptions> | import("../../config/resource-config.ts").ResourceConfig<"testserverPool", import("../../resources/testserver/resource.ts").TestserverPoolOptions, import("../../resources/testserver/provider.ts").TestserverPoolRequest, keyof import("../../resources/testserver/resource.ts").TestserverPoolOptions>)[]>;
|
|
215
|
+
readonly options: import("../../config/resource-config.ts").ResolvedResources<(import("../../config/resource-config.ts").ResourceConfig<"githubFixtureRepo", import("../../resources/github/resource.ts").GitHubFixtureRepoOptions, import("../../resources/github/config.ts").GitHubFixtureRepoSettings, keyof import("../../resources/github/resource.ts").GitHubFixtureRepoOptions> | import("../../config/resource-config.ts").ResourceConfig<"testserverPool", import("../../resources/testserver/resource.ts").TestserverPoolOptions, import("../../resources/testserver/provider.ts").TestserverPoolRequest, keyof import("../../resources/testserver/resource.ts").TestserverPoolOptions>)[]>;
|
|
216
|
+
readonly where: RunWhere;
|
|
217
|
+
readonly settlement: {
|
|
218
|
+
readonly ok: true;
|
|
219
|
+
} & import("../../core/command-slots.ts").ResourcesSettlement<import("../../resources.ts").Resources>;
|
|
220
|
+
}>;
|
|
221
|
+
export {};
|