@cnc-tools/storm 0.9.0 → 0.9.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.
Files changed (80) hide show
  1. package/bin/storm.js +3 -14
  2. package/dist/application.d.ts +18 -10
  3. package/dist/application.js +10 -11
  4. package/dist/bin/storm.js +97 -41
  5. package/dist/build-info.js +1 -1
  6. package/dist/chunks/chunk-5CQCRX2L.js +5768 -0
  7. package/dist/chunks/chunk-5U5Q6VZR.js +556 -0
  8. package/dist/chunks/chunk-7O6UN63H.js +63 -0
  9. package/dist/chunks/chunk-I5GZLOLQ.js +38 -0
  10. package/dist/chunks/chunk-NX55IJ5S.js +1842 -0
  11. package/dist/chunks/chunk-OCZJE5XV.js +910 -0
  12. package/dist/chunks/chunk-RRQ2ZGSE.js +1512 -0
  13. package/dist/chunks/chunk-S5NAIZYS.js +13 -0
  14. package/dist/chunks/chunk-UHO5OCEX.js +360 -0
  15. package/dist/chunks/chunk-WBIHJM7D.js +188 -0
  16. package/dist/chunks/chunk-WV6WQFC6.js +436 -0
  17. package/dist/chunks/live-app-X3PW2W42.js +89 -0
  18. package/dist/chunks/version-X7RMSKZI.js +12 -0
  19. package/dist/commands/exec/command.js +35 -21
  20. package/dist/commands/exec/metadata.js +66 -58
  21. package/dist/commands/exec/redaction.js +1 -1
  22. package/dist/commands/exec/run-collector.d.ts +1 -1
  23. package/dist/commands/exec/run-collector.js +1 -1
  24. package/dist/commands/exec/run-record.d.ts +1 -1
  25. package/dist/commands/exec/tests-summary.d.ts +1 -1
  26. package/dist/commands/exec/worker-chart.d.ts +1 -1
  27. package/dist/commands/runs/list/command.js +136 -33
  28. package/dist/commands/runs/list/metadata.js +22 -18
  29. package/dist/commands/runs/logs/command.js +131 -48
  30. package/dist/commands/runs/logs/metadata.js +24 -20
  31. package/dist/commands/runs/metadata.js +6 -2
  32. package/dist/commands/runs/past-run.d.ts +1 -1
  33. package/dist/commands/runs/past-run.js +1 -1
  34. package/dist/commands/runs/show/command.js +396 -74
  35. package/dist/commands/runs/show/metadata.js +24 -20
  36. package/dist/commands/vitest/command.js +195 -128
  37. package/dist/commands/vitest/metadata.js +45 -37
  38. package/dist/context.d.ts +1 -1
  39. package/dist/core/events.d.ts +1 -1
  40. package/dist/core/payload.d.ts +1 -1
  41. package/dist/core/payload.js +1 -1
  42. package/dist/core/provider.d.ts +12 -2
  43. package/dist/core/run.js +1 -1
  44. package/dist/live-app.d.ts +9 -0
  45. package/dist/live-app.js +21 -0
  46. package/dist/resource-commands.d.ts +13 -0
  47. package/dist/resource-commands.js +22 -0
  48. package/dist/resources/github/provider.d.ts +1 -1
  49. package/dist/resources/testserver/command-tree.d.ts +4 -0
  50. package/dist/resources/testserver/command-tree.js +12 -0
  51. package/dist/resources/testserver/commands/create/command.js +373 -194
  52. package/dist/resources/testserver/commands/create/metadata.js +52 -48
  53. package/dist/resources/testserver/commands/list/command.js +195 -50
  54. package/dist/resources/testserver/commands/list/metadata.js +12 -8
  55. package/dist/resources/testserver/provider.d.ts +1 -1
  56. package/dist/resources/testserver/resource-provider.js +2 -8
  57. package/dist/resources.d.ts +0 -3
  58. package/dist/resources.js +5 -10
  59. package/dist/runner/recipe.js +1 -1
  60. package/dist/runner/remote-command.js +1 -1
  61. package/dist/sdk/host.d.ts +2 -0
  62. package/dist/sdk/host.js +7 -0
  63. package/dist/version.d.ts +2 -2
  64. package/dist/version.js +10 -11
  65. package/dist/vitest/config.d.ts +4 -8
  66. package/dist/vitest/config.js +5 -9
  67. package/dist/vitest/container-scope.d.ts +12 -5
  68. package/dist/vitest/container-scope.js +27 -4
  69. package/dist/vitest/diagnostics.d.ts +8 -2
  70. package/dist/vitest/diagnostics.js +7 -4
  71. package/dist/vitest/fixtures.d.ts +4 -1
  72. package/dist/vitest/fixtures.js +17 -6
  73. package/dist/vitest/plan.d.ts +1 -1
  74. package/dist/vitest/plan.js +2 -2
  75. package/dist/vitest/sandbox.d.ts +6 -0
  76. package/dist/vitest/sandbox.js +6 -0
  77. package/package.json +4 -3
  78. package/bin/node-version.js +0 -24
  79. package/dist/closed-terminal.d.ts +0 -7
  80. package/dist/closed-terminal.js +0 -18
@@ -0,0 +1,13 @@
1
+ // src/resources/testserver/command-tree.ts
2
+ var testserverPoolCommandTree = {
3
+ mount: {
4
+ source: { id: "testserver" },
5
+ path: ["pool"],
6
+ description: "Inspect and maintain your pool of Testserver sandboxes."
7
+ },
8
+ directory: "resources/testserver/commands"
9
+ };
10
+
11
+ export {
12
+ testserverPoolCommandTree
13
+ };
@@ -0,0 +1,360 @@
1
+ import {
2
+ parseRunRecord,
3
+ timelineSchema
4
+ } from "./chunk-5U5Q6VZR.js";
5
+ import {
6
+ RESOURCE_REPORTS,
7
+ isoSecondsText,
8
+ sandboxPage,
9
+ seconds,
10
+ short,
11
+ snapshotPage
12
+ } from "./chunk-NX55IJ5S.js";
13
+ import {
14
+ parseTestEvent
15
+ } from "./chunk-5CQCRX2L.js";
16
+
17
+ // src/commands/runs/facts.ts
18
+ import { muted } from "@vercel/clinkr/vcli-kit";
19
+ import { z } from "zod";
20
+ var LOG_STEPS = ["command", "install", "build", "apply", "snapshot"];
21
+ var scopeSchema = z.discriminatedUnion("kind", [
22
+ z.object({
23
+ /** The runs of one config file. */
24
+ kind: z.literal("config"),
25
+ /** The config file found from the working directory, its absolute path. */
26
+ configFile: z.string()
27
+ }),
28
+ z.object({
29
+ /** Every run. */
30
+ kind: z.literal("all"),
31
+ /** `flag` for `--all`; `no-config-file` when no storm.config.ts was found from the working directory. */
32
+ why: z.enum(["flag", "no-config-file"])
33
+ })
34
+ ]);
35
+ var runFactsSchema = z.object({
36
+ /** The run id, its run directory's name. */
37
+ id: z.string(),
38
+ /** The run directory. */
39
+ path: z.string(),
40
+ /** Whether its run is still going. */
41
+ active: z.boolean(),
42
+ /** When it started, as an ISO time. */
43
+ startedAt: z.string().nullable(),
44
+ /** The working directory it ran in. */
45
+ cwd: z.string().nullable(),
46
+ /** The config file its settings came from; null when none applied, or unknown. */
47
+ configFile: z.string().nullable(),
48
+ /** The command after --. */
49
+ argv: z.array(z.string()).nullable(),
50
+ /** Where its command ran: on this machine (`local`, with --local), or in a runner sandbox (`runner`). */
51
+ where: z.discriminatedUnion("kind", [
52
+ z.object({ kind: z.literal("local") }),
53
+ z.object({
54
+ kind: z.literal("runner"),
55
+ /** The control plane team the runner sandbox ran in. */
56
+ team: z.string(),
57
+ /** The control plane project the runner sandbox ran in. */
58
+ project: z.string(),
59
+ /** The runner sandbox's region, such as iad1. */
60
+ region: z.string(),
61
+ /** The runner sandbox's runtime, such as node24. */
62
+ runtime: z.string(),
63
+ /** The runner sandbox's vCPUs. */
64
+ vcpus: z.number(),
65
+ /** The run's base: HEAD's merge-base with baseRef, a full SHA. */
66
+ base: z.string(),
67
+ /** The ref the base is HEAD's merge-base with, such as origin/main. */
68
+ baseRef: z.string(),
69
+ /** The runner sandbox's name; null until it started, or when the run stopped before it. */
70
+ sandbox: z.string().nullable(),
71
+ /** The runner sandbox's page in the Vercel dashboard, with what ran in it; null without a sandbox. */
72
+ sandboxUrl: z.string().nullable(),
73
+ /** When the runner sandbox's timeout stops it, as an ISO time, when the run kept it running once it ended so a person could connect to it; null when the run stopped and deleted it, or before the run ended. */
74
+ keptUntil: z.string().nullable(),
75
+ /** How many whole minutes are left until keptUntil, as of reading the run, 0 once it has passed; null when keptUntil is. */
76
+ keptMinutesLeft: z.number().nullable(),
77
+ /** The runner snapshot it started from: its id, the base it is of, which the run's changes went on top of, whether this run built it or reused it, for a branch snapshot the branch and HEAD commit of the run that saved it (each null for a base snapshot), and its page in the Vercel dashboard. Null until known. */
78
+ snapshot: z.object({
79
+ id: z.string(),
80
+ base: z.string(),
81
+ built: z.boolean(),
82
+ branch: z.string().nullable(),
83
+ head: z.string().nullable(),
84
+ url: z.string()
85
+ }).nullable(),
86
+ /** How saving the runner sandbox as a branch snapshot ended (--save-snapshot), as the run's ran result's runner.save says, with the saved snapshot's page in the Vercel dashboard (`url`, null unless saved); null without the flag. */
87
+ save: z.discriminatedUnion("kind", [
88
+ z.object({
89
+ kind: z.literal("saved"),
90
+ snapshotId: z.string(),
91
+ base: z.string(),
92
+ branch: z.string(),
93
+ head: z.string(),
94
+ ms: z.number(),
95
+ sizeBytes: z.number(),
96
+ entryWritten: z.boolean(),
97
+ url: z.string()
98
+ }),
99
+ z.object({ kind: z.literal("skipped"), reason: z.literal("detached-head") }),
100
+ z.object({
101
+ kind: z.literal("failed"),
102
+ step: z.enum(["scrub", "save-snapshot"]),
103
+ message: z.string()
104
+ }),
105
+ z.object({ kind: z.literal("stopped") })
106
+ ]).nullable()
107
+ })
108
+ ]).nullable(),
109
+ /** The Git checkout it started from: HEAD's branch (null when detached), its commit, and whether the working tree had uncommitted changes or untracked files. Null outside a Git checkout, or when unknown. */
110
+ git: z.object({ branch: z.string().nullable(), commit: z.string(), dirty: z.boolean() }).nullable(),
111
+ /** How it ended; null while it runs, or when unknown. */
112
+ ended: z.object({
113
+ /** The run's outcome: `ran` when its command ran, or why not, such as `canceled` or `spawn-failed`. */
114
+ outcome: z.string(),
115
+ /** The status storm exited with, when the command ran. */
116
+ exitCode: z.number().nullable(),
117
+ /** The signal that ended the command, if one did. */
118
+ signal: z.string().nullable(),
119
+ /** How long the command took, in milliseconds. */
120
+ ms: z.number().nullable(),
121
+ /** Its tests' totals, by their final results; null without one. */
122
+ tests: z.object({ passed: z.number(), failed: z.number(), skipped: z.number() }).nullable(),
123
+ /** Why its test results may be incomplete: a runner run's read of its test events file, once the command ended, failed with this message; null otherwise. */
124
+ testsIncomplete: z.string().nullable(),
125
+ /** What each resource it acquired reported, as a run's `ran` result's `resources`, such as the Testserver sandboxes and their log viewer URLs; null unless its command ran, or when unknown. */
126
+ resources: RESOURCE_REPORTS.ranSchema.nullable()
127
+ }).nullable()
128
+ });
129
+ function runFacts(run, now) {
130
+ const { record } = run;
131
+ return {
132
+ id: run.id,
133
+ path: run.path,
134
+ active: run.active,
135
+ startedAt: record?.startedAt ?? null,
136
+ cwd: record?.cwd ?? null,
137
+ configFile: record?.configFile ?? null,
138
+ argv: record === void 0 ? null : [...record.argv],
139
+ where: record === void 0 ? null : whereFacts(record.where, now),
140
+ git: record?.git === void 0 || record.git === null ? null : { ...record.git },
141
+ ended: record?.ended === void 0 ? null : {
142
+ ...record.ended,
143
+ tests: record.ended.tests === null ? null : { ...record.ended.tests }
144
+ }
145
+ };
146
+ }
147
+ function whereFacts(where, now) {
148
+ if (where.kind === "local") return { kind: "local" };
149
+ const { sandbox, snapshot, keptUntil, save } = where;
150
+ return {
151
+ ...where,
152
+ keptMinutesLeft: keptUntil === null ? null : Math.max(0, Math.floor((Date.parse(keptUntil) - now.getTime()) / 6e4)),
153
+ sandboxUrl: sandbox === null ? null : sandboxPage(where, sandbox),
154
+ snapshot: snapshot === null ? null : { ...snapshot, url: snapshotPage(where, snapshot.id) },
155
+ save: save?.kind === "saved" ? { ...save, url: snapshotPage(where, save.snapshotId) } : save
156
+ };
157
+ }
158
+ function scopeFacts(scope) {
159
+ return scope.kind === "config" ? { kind: "config", configFile: scope.configFile } : { kind: "all", why: scope.why };
160
+ }
161
+ function scopeText(scope) {
162
+ if (scope.kind === "config") return scope.configFile;
163
+ return scope.why === "flag" ? "every config (--all)" : "every config (no storm.config.ts found)";
164
+ }
165
+ var runsUnreadable = {
166
+ exitCode: 1,
167
+ description: "storm couldn't read the run directories.",
168
+ schema: z.object({
169
+ /** The directory or file the read failed on. */
170
+ path: z.string(),
171
+ /** What the OS said, or why there is no place for run directories. */
172
+ message: z.string()
173
+ }),
174
+ render: ({ path, message }) => ({
175
+ message: `Couldn't read the run directories: ${message}`,
176
+ rows: [["Path", path]]
177
+ })
178
+ };
179
+ var runNotFound = {
180
+ exitCode: 1,
181
+ description: "No run directory has the id given: it was never a run on this machine, or it was removed.",
182
+ schema: z.object({
183
+ /** The run id given. */
184
+ id: z.string()
185
+ }),
186
+ render: ({ id }) => ({
187
+ message: `Couldn't find run ${id}.`,
188
+ next: [{ type: "command", argv: ["storm", "runs", "list", "--all"], label: "List every run" }]
189
+ })
190
+ };
191
+ function exitText(run) {
192
+ if (run.active) return "running";
193
+ const { ended } = run;
194
+ if (ended === null) return "-";
195
+ if (ended.outcome !== "ran") return ended.outcome;
196
+ if (ended.exitCode === null) return "-";
197
+ return ended.signal === null ? String(ended.exitCode) : `${ended.exitCode} (${ended.signal})`;
198
+ }
199
+ function exitTone(run) {
200
+ if (run.active) return "accent";
201
+ const { ended } = run;
202
+ if (ended === null) return void 0;
203
+ if (ended.outcome === "canceled") return "warn";
204
+ if (ended.outcome !== "ran") return "error";
205
+ if (ended.exitCode === null) return void 0;
206
+ return ended.exitCode === 0 ? "success" : "error";
207
+ }
208
+ function tookText(run) {
209
+ const ms = run.ended?.ms;
210
+ return ms === void 0 || ms === null ? "-" : seconds(ms);
211
+ }
212
+ function totalsText(run) {
213
+ const totals = run.ended?.tests;
214
+ if (totals === void 0 || totals === null) return "-";
215
+ const parts = [
216
+ ...totals.passed > 0 ? [`${totals.passed} passed`] : [],
217
+ ...totals.failed > 0 ? [`${totals.failed} failed`] : [],
218
+ ...totals.skipped > 0 ? [`${totals.skipped} skipped`] : []
219
+ ];
220
+ return parts.length === 0 ? "no tests" : parts.join(" \xB7 ");
221
+ }
222
+ function totalsTone(run) {
223
+ const totals = run.ended?.tests;
224
+ if (totals === void 0 || totals === null) return void 0;
225
+ if (totals.failed > 0) return "error";
226
+ return totals.passed > 0 ? "success" : void 0;
227
+ }
228
+ function runnerCell(run) {
229
+ const { where } = run;
230
+ if (where === null) return muted("-");
231
+ if (where.kind === "local") return muted("local");
232
+ if (where.sandbox === null || where.sandboxUrl === null)
233
+ return muted(run.ended === null ? "(starting)" : "(none started)");
234
+ const left = where.keptMinutesLeft;
235
+ return {
236
+ text: left === null || left === 0 ? where.sandbox : `${where.sandbox} (${left}m left)`,
237
+ url: where.sandboxUrl
238
+ };
239
+ }
240
+ function keptText(run) {
241
+ const { where } = run;
242
+ if (where === null || where.kind === "local" || where.keptUntil === null) return void 0;
243
+ const until = `until ${isoSecondsText(where.keptUntil)}`;
244
+ return where.keptMinutesLeft === null || where.keptMinutesLeft === 0 ? `${until} (stopped by now)` : `${until} (${where.keptMinutesLeft}m left)`;
245
+ }
246
+ function branchText(run) {
247
+ if (run.git === null) return "-";
248
+ return run.git.branch ?? "detached";
249
+ }
250
+ function gitText(run) {
251
+ const { git } = run;
252
+ if (git === null) return "-";
253
+ const at = `${git.branch ?? "detached"} at ${short(git.commit)}`;
254
+ return git.dirty ? `${at}, plus uncommitted changes` : at;
255
+ }
256
+ function startedText(run) {
257
+ return run.startedAt === null ? "-" : isoSecondsText(run.startedAt);
258
+ }
259
+ function commandText(run) {
260
+ if (run.argv === null) return "-";
261
+ return run.argv.map((arg) => /^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replaceAll("'", `'\\''`)}'`).join(" ");
262
+ }
263
+
264
+ // src/commands/runs/past-run.ts
265
+ function runScope(all, configFile) {
266
+ if (all) return { kind: "all", why: "flag" };
267
+ if (configFile === void 0) return { kind: "all", why: "no-config-file" };
268
+ return { kind: "config", configFile };
269
+ }
270
+ function runsInScope(listed, scope) {
271
+ const runs = listed.map(({ id, path, active, run }) => ({ id, path, active, record: parseRunRecord(run) }));
272
+ return scope.kind === "all" ? runs : runs.filter(({ record }) => record?.configFile === scope.configFile);
273
+ }
274
+ function onBranch(runs, branch) {
275
+ return branch === void 0 ? runs : runs.filter(({ record }) => record?.git?.branch === branch);
276
+ }
277
+ function newestFinished(runs) {
278
+ return runs.find((run) => !run.active && run.record?.ended !== void 0);
279
+ }
280
+ function newest(runs) {
281
+ return runs[0];
282
+ }
283
+ function pastRun(directory) {
284
+ const parsed = (directory.tests ?? []).map(parseTestEvent);
285
+ return {
286
+ id: directory.id,
287
+ path: directory.path,
288
+ active: directory.active,
289
+ record: parseRunRecord(directory.run),
290
+ finished: directory.tests !== void 0,
291
+ events: parsed.filter((event) => event !== void 0),
292
+ unreadableTestLines: parsed.filter((event) => event === void 0).length,
293
+ timeline: parseTimeline(directory.timeline)
294
+ };
295
+ }
296
+ function finalResults(events) {
297
+ return events.flatMap((event) => event.kind === "test-result" ? [event] : []);
298
+ }
299
+ function selected(result, filters) {
300
+ if (filters.failed && result.state !== "fail") return false;
301
+ if (filters.test !== void 0 && !result.test.includes(filters.test) && !result.file.includes(filters.test))
302
+ return false;
303
+ return true;
304
+ }
305
+ function parseTimeline(text) {
306
+ if (text === void 0) return void 0;
307
+ let json;
308
+ try {
309
+ json = JSON.parse(text);
310
+ } catch {
311
+ return void 0;
312
+ }
313
+ const parsed = timelineSchema.safeParse(json);
314
+ return parsed.success ? parsed.data : void 0;
315
+ }
316
+ function timelineFromFacts(facts) {
317
+ return {
318
+ ...facts,
319
+ rows: facts.rows.map((row) => ({
320
+ ...row,
321
+ // `timelineSchema`'s step names are the timeline's, though its enum, built from each resource's presentation,
322
+ // types them as strings.
323
+ steps: row.steps.map((step) => ({ ...step, name: step.name })),
324
+ // A timeline row always has these keys, undefined when it has no such fact; the facts leave them out then.
325
+ snapshot: row.snapshot,
326
+ sandboxes: row.sandboxes
327
+ }))
328
+ };
329
+ }
330
+
331
+ export {
332
+ LOG_STEPS,
333
+ scopeSchema,
334
+ runFactsSchema,
335
+ runFacts,
336
+ scopeFacts,
337
+ scopeText,
338
+ runsUnreadable,
339
+ runNotFound,
340
+ exitText,
341
+ exitTone,
342
+ tookText,
343
+ totalsText,
344
+ totalsTone,
345
+ runnerCell,
346
+ keptText,
347
+ branchText,
348
+ gitText,
349
+ startedText,
350
+ commandText,
351
+ runScope,
352
+ runsInScope,
353
+ onBranch,
354
+ newestFinished,
355
+ newest,
356
+ pastRun,
357
+ finalResults,
358
+ selected,
359
+ timelineFromFacts
360
+ };
@@ -0,0 +1,188 @@
1
+ // src/vitest/sandbox.ts
2
+ var WORKERS_PER_SANDBOX = 4;
3
+
4
+ // src/vitest/list-output.ts
5
+ import { z } from "zod";
6
+ var VITEST_LIST = z.array(z.looseObject({ name: z.string(), file: z.string() }));
7
+ function readVitestList(stdout) {
8
+ let document;
9
+ try {
10
+ document = JSON.parse(stdout);
11
+ } catch {
12
+ throw new Error("`vitest list --json` did not print JSON");
13
+ }
14
+ const parsed = VITEST_LIST.safeParse(document);
15
+ if (!parsed.success) throw new Error("`vitest list --json` did not print a list of tests");
16
+ return parsed.data.map(({ name, file }) => ({ name, file }));
17
+ }
18
+
19
+ // src/vitest/live/list-gateway.ts
20
+ import { spawn } from "node:child_process";
21
+ import { constants } from "node:fs";
22
+ import { access } from "node:fs/promises";
23
+ import { join as join2 } from "node:path";
24
+
25
+ // src/vitest/find-vitest.ts
26
+ import { dirname, join, relative, isAbsolute } from "node:path";
27
+ var VITEST_BIN = join("node_modules", ".bin", "vitest");
28
+ function vitestSearchDirectories(from, root) {
29
+ const inside = from === root || isInside(root, from);
30
+ const directories = [];
31
+ let directory = from;
32
+ for (; ; ) {
33
+ directories.push(directory);
34
+ if (inside && directory === root) return directories;
35
+ const parent = dirname(directory);
36
+ if (parent === directory) return directories;
37
+ directory = parent;
38
+ }
39
+ }
40
+ function isInside(directory, path) {
41
+ const between = relative(directory, path);
42
+ return between !== "" && !between.startsWith("..") && !isAbsolute(between);
43
+ }
44
+
45
+ // src/vitest/live/list-gateway.ts
46
+ var liveVitestListGateway = {
47
+ async findVitest({ from, root }) {
48
+ const searched = vitestSearchDirectories(from, root);
49
+ for (const directory of searched) {
50
+ const path = join2(directory, VITEST_BIN);
51
+ try {
52
+ await access(path, constants.X_OK);
53
+ return { ok: true, path };
54
+ } catch {
55
+ }
56
+ }
57
+ return { ok: false, searched };
58
+ },
59
+ listTests(request) {
60
+ return new Promise((resolve) => {
61
+ let settled = false;
62
+ const settle = (result) => {
63
+ if (settled) return;
64
+ settled = true;
65
+ resolve(result);
66
+ };
67
+ const timeout = AbortSignal.timeout(request.timeoutMs);
68
+ const child = spawn(request.executable ?? "vitest", listArgv(request.args), {
69
+ ...request.cwd === void 0 ? {} : { cwd: request.cwd },
70
+ stdio: ["ignore", "pipe", "pipe"],
71
+ signal: request.signal === void 0 ? timeout : AbortSignal.any([timeout, request.signal])
72
+ });
73
+ let stopped;
74
+ let stdout = "";
75
+ let stderr = "";
76
+ child.stdout.setEncoding("utf8").on("data", (chunk) => {
77
+ stdout += chunk;
78
+ });
79
+ child.stderr.setEncoding("utf8").on("data", (chunk) => {
80
+ stderr += chunk;
81
+ });
82
+ child.on("error", (error) => {
83
+ if (error.name !== "AbortError") {
84
+ settle({ ok: false, failure: { kind: "start-failed", message: error.message } });
85
+ return;
86
+ }
87
+ stopped = request.signal?.aborted === true ? { kind: "canceled" } : { kind: "timed-out", timeoutMs: request.timeoutMs };
88
+ if (child.exitCode !== null || child.signalCode !== null) settle({ ok: false, failure: stopped });
89
+ });
90
+ child.on("exit", () => {
91
+ if (stopped !== void 0) settle({ ok: false, failure: stopped });
92
+ });
93
+ child.on("close", (exitCode, signal) => {
94
+ if (stopped !== void 0) {
95
+ settle({ ok: false, failure: stopped });
96
+ return;
97
+ }
98
+ if (exitCode !== 0) {
99
+ settle({ ok: false, failure: { kind: "exited", exitCode, signal, lastStderrLine: lastLine(stderr) } });
100
+ return;
101
+ }
102
+ try {
103
+ settle({ ok: true, tests: readVitestList(stdout) });
104
+ } catch (error) {
105
+ settle({ ok: false, failure: { kind: "unreadable-output", message: error.message } });
106
+ }
107
+ });
108
+ });
109
+ }
110
+ };
111
+ function lastLine(text) {
112
+ return text.split(/\r?\n/).map((line) => line.trim()).findLast((line) => line !== "" && !/^at\s/.test(line)) ?? "";
113
+ }
114
+ function listArgv(args) {
115
+ const end = args.indexOf("--");
116
+ return end === -1 ? ["list", ...args, "--json"] : ["list", ...args.slice(0, end), "--json", ...args.slice(end)];
117
+ }
118
+
119
+ // src/vitest/plan.ts
120
+ var LIST_TIMEOUT_MS = 6e4;
121
+ async function planVitestRun(options, gateway = liveVitestListGateway) {
122
+ const timeoutMs = options.timeoutMs ?? LIST_TIMEOUT_MS;
123
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
124
+ throw new TypeError(`planVitestRun: timeoutMs is ${String(timeoutMs)}, not a positive number`);
125
+ }
126
+ const listed = await gateway.listTests({
127
+ args: options.args,
128
+ ...options.cwd === void 0 ? {} : { cwd: options.cwd },
129
+ ...options.executable === void 0 ? {} : { executable: options.executable },
130
+ timeoutMs,
131
+ ...options.signal === void 0 ? {} : { signal: options.signal }
132
+ });
133
+ return listed.ok ? { ok: true, plan: planOf(listed.tests) } : { ok: false, failure: listed.failure };
134
+ }
135
+ function vitestRunArgv(executable, args) {
136
+ return [executable, "run", ...args];
137
+ }
138
+ function formatPlan(plan) {
139
+ return `${plan.tests} ${plan.tests === 1 ? "test" : "tests"} in ${plan.files} ${plan.files === 1 ? "file" : "files"}`;
140
+ }
141
+ var AUTO_SANDBOXES_MAX = 8;
142
+ function autoSandboxes(files) {
143
+ return sandboxesFor(files, AUTO_SANDBOXES_MAX);
144
+ }
145
+ function sandboxesFor(files, max, workersPerSandbox = WORKERS_PER_SANDBOX) {
146
+ if (!Number.isInteger(files) || files < 0) {
147
+ throw new TypeError(`sandboxesFor: files is ${String(files)}, not a non-negative integer`);
148
+ }
149
+ for (const [name, value] of [
150
+ ["max", max],
151
+ ["workersPerSandbox", workersPerSandbox]
152
+ ]) {
153
+ if (!Number.isInteger(value) || value < 1) {
154
+ throw new TypeError(`sandboxesFor: ${name} is ${String(value)}, not a positive integer`);
155
+ }
156
+ }
157
+ return Math.min(max, Math.max(1, Math.ceil(files / workersPerSandbox)));
158
+ }
159
+ function planOf(tests) {
160
+ return { tests: tests.length, files: new Set(tests.map((test) => test.file)).size };
161
+ }
162
+ function describeVitestListFailure(failure) {
163
+ switch (failure.kind) {
164
+ case "start-failed":
165
+ return `\`vitest list\` failed to start: ${failure.message}`;
166
+ case "timed-out":
167
+ return `\`vitest list\` did not finish in ${failure.timeoutMs / 1e3}s`;
168
+ case "exited": {
169
+ const how = failure.exitCode === null ? `was ended by ${failure.signal ?? "a signal"}` : `exited ${failure.exitCode}`;
170
+ return `\`vitest list\` ${how}${failure.lastStderrLine === "" ? "" : `: ${failure.lastStderrLine}`}`;
171
+ }
172
+ case "unreadable-output":
173
+ return failure.message;
174
+ case "canceled":
175
+ return "`vitest list` was canceled";
176
+ }
177
+ }
178
+
179
+ export {
180
+ WORKERS_PER_SANDBOX,
181
+ liveVitestListGateway,
182
+ planVitestRun,
183
+ vitestRunArgv,
184
+ formatPlan,
185
+ AUTO_SANDBOXES_MAX,
186
+ autoSandboxes,
187
+ describeVitestListFailure
188
+ };