@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.
Files changed (113) hide show
  1. package/dist/build-info.js +1 -1
  2. package/dist/combine-errors.js +2 -2
  3. package/dist/commands/dashboard.js +1 -1
  4. package/dist/commands/{run → exec}/cleanup.d.ts +1 -1
  5. package/dist/commands/{run → exec}/cleanup.js +1 -1
  6. package/dist/commands/{run/outcomes.d.ts → exec/command.d.ts} +77 -112
  7. package/dist/commands/exec/command.js +23 -0
  8. package/dist/commands/{run → exec}/job-summary.d.ts +5 -1
  9. package/dist/commands/{run → exec}/job-summary.js +5 -2
  10. package/dist/commands/exec/metadata.d.ts +66 -0
  11. package/dist/commands/exec/metadata.js +55 -0
  12. package/dist/commands/{run → exec}/mint-failed.js +4 -4
  13. package/dist/commands/exec/outcomes.d.ts +614 -0
  14. package/dist/commands/exec/outcomes.js +338 -0
  15. package/dist/commands/exec/run-command.d.ts +221 -0
  16. package/dist/commands/exec/run-command.js +663 -0
  17. package/dist/commands/exec/run-metadata.d.ts +56 -0
  18. package/dist/commands/exec/run-metadata.js +58 -0
  19. package/dist/commands/{run → exec}/run-record.d.ts +27 -1
  20. package/dist/commands/{run → exec}/run-record.js +8 -0
  21. package/dist/commands/exec/testserver-flags.d.ts +48 -0
  22. package/dist/commands/exec/testserver-flags.js +80 -0
  23. package/dist/commands/runs/facts.js +2 -2
  24. package/dist/commands/runs/logs/metadata.js +1 -1
  25. package/dist/commands/runs/logs/outcomes.js +4 -1
  26. package/dist/commands/runs/past-run.d.ts +2 -2
  27. package/dist/commands/runs/past-run.js +2 -2
  28. package/dist/commands/runs/show/metadata.js +2 -2
  29. package/dist/commands/runs/show/outcomes.js +7 -4
  30. package/dist/commands/vitest/command.d.ts +299 -0
  31. package/dist/commands/vitest/command.js +138 -0
  32. package/dist/commands/vitest/metadata.d.ts +66 -0
  33. package/dist/commands/vitest/metadata.js +35 -0
  34. package/dist/commands/vitest/outcomes.d.ts +273 -0
  35. package/dist/commands/vitest/outcomes.js +77 -0
  36. package/dist/config/index.d.ts +2 -1
  37. package/dist/config/index.js +1 -0
  38. package/dist/config/resolve.d.ts +3 -3
  39. package/dist/config/resolve.js +3 -3
  40. package/dist/config/resource-config.d.ts +2 -2
  41. package/dist/config/schema.d.ts +1 -1
  42. package/dist/config/set.d.ts +15 -4
  43. package/dist/config/set.js +28 -12
  44. package/dist/config-file/define.d.ts +8 -6
  45. package/dist/context.d.ts +6 -3
  46. package/dist/context.js +4 -2
  47. package/dist/core/command-provider.d.ts +1 -1
  48. package/dist/core/presentation.js +1 -1
  49. package/dist/core/presentations.js +1 -1
  50. package/dist/resources/testserver/command.d.ts +1 -1
  51. package/dist/resources/testserver/command.js +1 -1
  52. package/dist/resources/testserver/config.d.ts +1 -1
  53. package/dist/resources/testserver/config.js +3 -2
  54. package/dist/resources/testserver/credential-facts.js +1 -1
  55. package/dist/resources/testserver/resource.d.ts +2 -2
  56. package/dist/resources/testserver/sandbox/create.d.ts +2 -2
  57. package/dist/resources/testserver/sandbox/create.js +2 -2
  58. package/dist/resources.d.ts +9 -6
  59. package/dist/resources.js +3 -3
  60. package/dist/sdk/index.js +1 -1
  61. package/dist/sdk/payload/payload.d.ts +2 -2
  62. package/dist/sdk/payload/payload.js +2 -2
  63. package/dist/vercel-cli/driver.d.ts +1 -1
  64. package/dist/vercel-cli/entry.d.ts +1 -1
  65. package/dist/vercel-cli/entry.js +1 -1
  66. package/dist/vercel-cli/verbose.d.ts +2 -2
  67. package/dist/vercel-cli/verbose.js +2 -2
  68. package/dist/vitest/config.d.ts +5 -5
  69. package/dist/vitest/config.js +5 -5
  70. package/dist/vitest/find-vitest.d.ts +7 -0
  71. package/dist/vitest/find-vitest.js +28 -0
  72. package/dist/vitest/fixtures.d.ts +2 -2
  73. package/dist/vitest/fixtures.js +3 -3
  74. package/dist/vitest/gateways.d.ts +37 -6
  75. package/dist/vitest/gateways.js +3 -2
  76. package/dist/vitest/live/list-gateway.d.ts +7 -3
  77. package/dist/vitest/live/list-gateway.js +55 -8
  78. package/dist/vitest/plan.d.ts +41 -8
  79. package/dist/vitest/plan.js +47 -16
  80. package/dist/vitest/sandbox.d.ts +1 -1
  81. package/dist/vitest/sandbox.js +1 -1
  82. package/dist/vitest/test-events.d.ts +2 -2
  83. package/dist/vitest/test-events.js +3 -3
  84. package/dist/vitest/test-results.d.ts +1 -1
  85. package/dist/vitest/test-results.js +1 -1
  86. package/dist/vitest/types.d.ts +1 -1
  87. package/package.json +2 -2
  88. package/skills/overview.md +5 -4
  89. package/skills/read-run-output.md +1 -1
  90. package/dist/commands/run/command.d.ts +0 -327
  91. package/dist/commands/run/command.js +0 -620
  92. package/dist/commands/run/metadata.d.ts +0 -47
  93. package/dist/commands/run/metadata.js +0 -83
  94. package/dist/commands/run/outcomes.js +0 -332
  95. /package/dist/commands/{run → exec}/live-view.d.ts +0 -0
  96. /package/dist/commands/{run → exec}/live-view.js +0 -0
  97. /package/dist/commands/{run → exec}/mint-failed.d.ts +0 -0
  98. /package/dist/commands/{run → exec}/progress.d.ts +0 -0
  99. /package/dist/commands/{run → exec}/progress.js +0 -0
  100. /package/dist/commands/{run → exec}/redaction.d.ts +0 -0
  101. /package/dist/commands/{run → exec}/redaction.js +0 -0
  102. /package/dist/commands/{run → exec}/run-collector.d.ts +0 -0
  103. /package/dist/commands/{run → exec}/run-collector.js +0 -0
  104. /package/dist/commands/{run → exec}/tests-summary.d.ts +0 -0
  105. /package/dist/commands/{run → exec}/tests-summary.js +0 -0
  106. /package/dist/commands/{run → exec}/text.d.ts +0 -0
  107. /package/dist/commands/{run → exec}/text.js +0 -0
  108. /package/dist/commands/{run → exec}/view.d.ts +0 -0
  109. /package/dist/commands/{run → exec}/view.js +0 -0
  110. /package/dist/commands/{run → exec}/waterfall.d.ts +0 -0
  111. /package/dist/commands/{run → exec}/waterfall.js +0 -0
  112. /package/dist/commands/{run → exec}/worker-chart.d.ts +0 -0
  113. /package/dist/commands/{run → exec}/worker-chart.js +0 -0
@@ -112,7 +112,7 @@ export declare const testserverPoolRefusalErrors: {
112
112
  /**
113
113
  * The Testserver pool resource's command half, `resources.testserverPool`, with its errors: its prepare's,
114
114
  * `pool_unavailable`, and its refusal errors. A failed mint with no Testserver sandbox in hand ends the run as the
115
- * run's own `mint_failed`, which the `run` command defines.
115
+ * run's own `mint_failed`, which `exec` and `vitest` define.
116
116
  */
117
117
  export declare const testserverPoolCommand: {
118
118
  errors: import("@vercel/clinkr").SharedErrors<{
@@ -185,7 +185,7 @@ export const testserverPoolRefusalErrors = defineRefusals({
185
185
  /**
186
186
  * The Testserver pool resource's command half, `resources.testserverPool`, with its errors: its prepare's,
187
187
  * `pool_unavailable`, and its refusal errors. A failed mint with no Testserver sandbox in hand ends the run as the
188
- * run's own `mint_failed`, which the `run` command defines.
188
+ * run's own `mint_failed`, which `exec` and `vitest` define.
189
189
  */
190
190
  export const testserverPoolCommand = {
191
191
  errors: testserverPoolPrepareErrors,
@@ -9,7 +9,7 @@ import type { TestserverPoolOptions } from "./resource.ts";
9
9
  export type TestserverPoolSettings = TestserverPoolRequest;
10
10
  /**
11
11
  * The Testserver pool resource's config. Every option has a default, so a run that holds the resource, by the file or
12
- * by a `--set` of any option, has them all. Its checks across options:
12
+ * by a flag for any option, has them all. Its checks across options:
13
13
  *
14
14
  * - under `noCreate`, which creates no Testserver sandbox, a `ttl` from a flag is refused, and the file's is unused;
15
15
  * - otherwise the `ttl` must be longer than `minTimeLeft`, or no Testserver sandbox the run created would have the time
@@ -1,5 +1,6 @@
1
1
  // The Testserver pool resource's config: its section `resources.testserverPool` in `storm.config.ts`, the rule
2
- // and default of each option, and the checks across its options. `config` loads, reads `--set` and merges against it;
2
+ // and default of each option, and the checks across its options. `config` loads and merges against it, and `exec` and
3
+ // `vitest` check their own `--testserver-<option>` flags with its rules;
3
4
  // the command half (`command.ts`) settles the resolved options into the run's request.
4
5
  import { checkBoolean, checkNonEmptyString, describeValue, optionKeyPath, readBooleanText, readTextAsIs, readWholeNumberText, wrongValue, } from "../../config/index.js";
5
6
  import { parseDuration, parseTtl } from "../../time/index.js";
@@ -26,7 +27,7 @@ function ttl(value) {
26
27
  const KIND = "testserverPool";
27
28
  /**
28
29
  * The Testserver pool resource's config. Every option has a default, so a run that holds the resource, by the file or
29
- * by a `--set` of any option, has them all. Its checks across options:
30
+ * by a flag for any option, has them all. Its checks across options:
30
31
  *
31
32
  * - under `noCreate`, which creates no Testserver sandbox, a `ttl` from a flag is refused, and the file's is unused;
32
33
  * - otherwise the `ttl` must be longer than `minTimeLeft`, or no Testserver sandbox the run created would have the time
@@ -1,4 +1,4 @@
1
- // How the Testserver pool's `run` errors and `pool create` report a credential source's failures: a failed GitHub
1
+ // How the Testserver pool's run errors and `pool create` report a credential source's failures: a failed GitHub
2
2
  // Actions OIDC token request, and where a rejected credential came from.
3
3
  import { z } from "zod";
4
4
  import { describeTokenRequestFailure, rejectedCredentialFix, } from "../../credential/index.js";
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The Testserver pool resource's options: the Testserver sandboxes a run holds for its command. `storm run
3
- * --set resources.testserverPool.<option>=<value>` overrides each one, and `pool create` reads `build` and `ttl`.
2
+ * The Testserver pool resource's options: the Testserver sandboxes a run holds for its command. `storm vitest`
3
+ * and `storm exec` override each one with its own flag, `--testserver-<option>`, and `pool create` reads `build` and `ttl`.
4
4
  */
5
5
  export interface TestserverPoolOptions {
6
6
  /** How many Testserver sandboxes a run gets: 1 to 32; 1 by default. */
@@ -2,8 +2,8 @@ import type { Credential } from "../../../credential/index.ts";
2
2
  import type { ControlPlaneGateway, CreateOutcome, CreateProgress } from "./gateways.ts";
3
3
  import type { Timer } from "../../../time/index.ts";
4
4
  /**
5
- * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `--set` of it, or `pool
6
- * create --ttl`) says otherwise: 5 hours.
5
+ * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `run --testserver-ttl`,
6
+ * or `pool create --ttl`) says otherwise: 5 hours.
7
7
  */
8
8
  export declare const DEFAULT_TTL_MINUTES = 300;
9
9
  /** A TTL as a person reads it: `5 hours`, `1 hour`, `30 minutes`, `90 minutes`. */
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `--set` of it, or `pool
3
- * create --ttl`) says otherwise: 5 hours.
2
+ * The TTL a Testserver sandbox gets unless the `ttl` setting (`resources.testserverPool.ttl`, `run --testserver-ttl`,
3
+ * or `pool create --ttl`) says otherwise: 5 hours.
4
4
  */
5
5
  export const DEFAULT_TTL_MINUTES = 300;
6
6
  /** A TTL as a person reads it: `5 hours`, `1 hour`, `30 minutes`, `90 minutes`. */
@@ -1,4 +1,4 @@
1
- import { type StormCleanupFacts } from "./commands/run/cleanup.ts";
1
+ import { type StormCleanupFacts } from "./commands/exec/cleanup.ts";
2
2
  import type { CommandMount } from "@vercel/clinkr";
3
3
  import type { AnyResourceConfig, GivenResources, OptionsResolution, ResolvedResources } from "./config/index.ts";
4
4
  import type { StormContext } from "./context.ts";
@@ -282,19 +282,22 @@ export type FittingResourceConfig<K> = {
282
282
  export declare const RESOURCE_CONFIGS: (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>)[];
283
283
  /** Each held resource's resolved options, by name; a resource the run doesn't hold is absent. */
284
284
  export type StormResourceOptions = ResolvedResources<typeof RESOURCE_CONFIGS>;
285
- /** The values `--set` gave, by resource, then by option. */
285
+ /**
286
+ * The resource options the command line gave, by resource, then by option: each from a `--set`, or from a run's own
287
+ * flag for the option (`exec`'s and `vitest`'s).
288
+ */
286
289
  export type StormSetValues = GivenResources<typeof RESOURCE_CONFIGS>;
287
290
  /** Every resource's reports: its cleanup and what a ran outcome says of it, and what the host does for it. */
288
291
  export declare const RESOURCE_REPORTS: import("./core/command-slots.ts").ResourceReports<Resources>;
289
292
  /** How every resource shows in a run's progress: its own events' lines, and its lane's rows and label. */
290
293
  export declare const RESOURCE_PRESENTATIONS: import("./core/presentations.ts").ResourcePresentations<Resources>;
291
294
  /** The run's cleanup, as every outcome after the run starts acquiring reports it: the runner's and each resource's. */
292
- export declare const RUN_CLEANUP: import("./commands/run/cleanup.ts").RunCleanup;
295
+ export declare const RUN_CLEANUP: import("./commands/exec/cleanup.ts").RunCleanup;
293
296
  /**
294
- * Every error a resource's command half defines, which the `run` command lists: the errors that end a run before it
297
+ * Every error a resource's command half defines, which `exec` and `vitest` list: the errors that end a run before it
295
298
  * holds anything, in provider order, then the refusal errors, in provider order, each carrying the run's cleanup.
296
299
  */
297
- export declare const RESOURCE_ERRORS: import("./commands/run/cleanup.ts").WithCleanup<{
300
+ export declare const RESOURCE_ERRORS: import("./commands/exec/cleanup.ts").WithCleanup<{
298
301
  readonly githubFixtureRepoUnavailable: import("@vercel/clinkr").DataErrorDefinition<import("zod").ZodObject<{
299
302
  repo: import("zod").ZodString;
300
303
  status: import("zod").ZodNullable<import("zod").ZodNumber>;
@@ -406,7 +409,7 @@ export declare const RESOURCE_ERRORS: import("./commands/run/cleanup.ts").WithCl
406
409
  }, import("zod/v4/core").$strip>;
407
410
  }>;
408
411
  /**
409
- * Every resource's command half, bound to its name: what the `run` command settles and reports through, and
412
+ * Every resource's command half, bound to its name: what `exec` and `vitest` settle and report through, and
410
413
  * `refusedError`, the error a run a resource refused ends with: the refusal error its facts name, built with the run's
411
414
  * cleanup.
412
415
  */
package/dist/resources.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // `Resources`, so commands never spell the generic. A resource folder is reached only through its provider value, and
6
6
  // only this file takes one; `.oxlintrc.json` enforces it.
7
7
  import { combineErrors } from "./combine-errors.js";
8
- import { runCleanupOf } from "./commands/run/cleanup.js";
8
+ import { runCleanupOf } from "./commands/exec/cleanup.js";
9
9
  import { applyRunEvent, bindCommands, resourcePresentations, resourceReports, timeline, } from "./core/index.js";
10
10
  import { githubFixtureRepoProvider } from "./resources/github/index.js";
11
11
  import { testserverPoolProvider } from "./resources/testserver/index.js";
@@ -43,7 +43,7 @@ export const RUN_CLEANUP = runCleanupOf(RESOURCE_REPORTS);
43
43
  */
44
44
  const REFUSALS = RUN_CLEANUP.withCleanup(combineErrors(PROVIDERS.map(({ command }) => command.refusalErrors)));
45
45
  /**
46
- * Every error a resource's command half defines, which the `run` command lists: the errors that end a run before it
46
+ * Every error a resource's command half defines, which `exec` and `vitest` list: the errors that end a run before it
47
47
  * holds anything, in provider order, then the refusal errors, in provider order, each carrying the run's cleanup.
48
48
  */
49
49
  export const RESOURCE_ERRORS = combineErrors([
@@ -52,7 +52,7 @@ export const RESOURCE_ERRORS = combineErrors([
52
52
  ]);
53
53
  const BOUND = bindCommands(PROVIDER_LIST);
54
54
  /**
55
- * Every resource's command half, bound to its name: what the `run` command settles and reports through, and
55
+ * Every resource's command half, bound to its name: what `exec` and `vitest` settle and report through, and
56
56
  * `refusedError`, the error a run a resource refused ends with: the refusal error its facts name, built with the run's
57
57
  * cleanup.
58
58
  */
package/dist/sdk/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // The storm SDK's published surface, exported as `@cnc-tools/storm/sdk`: only what a command uses. A command
2
- // running under `storm run` uses it to read the run payload, start containers, seed them through factories or
2
+ // running under a storm run uses it to read the run payload, start containers, seed them through factories or
3
3
  // the seeder's entity-level calls, send them API requests, warm their services, read their logs, and proxy clients
4
4
  // that can't send a test id. The gateway seams the SDK's own tests and fakes need live on each SDK module's
5
5
  // `index.ts`, not here. The Vitest adapter (`src/vitest/`, `@cnc-tools/storm/vitest`) builds on this surface;
@@ -26,7 +26,7 @@ export interface RunPayloadResources {
26
26
  /**
27
27
  * The run payload, version 2: the resources the run holds (`resources`); where the command may append test events
28
28
  * (`testEvents`, a file path), when the run follows them; and whether the run is verbose (`verbose`, under
29
- * `storm run --verbose`), so the command prints what each test did as it goes, passing or not.
29
+ * `storm vitest --verbose` or `storm exec --verbose`), so the command prints what each test did as it goes, passing or not.
30
30
  */
31
31
  export interface RunPayload {
32
32
  readonly version: 2;
@@ -41,7 +41,7 @@ export declare class RunPayloadError extends Error {
41
41
  readonly name = "RunPayloadError";
42
42
  }
43
43
  /**
44
- * The run payload in `env`'s `STORM_RUN`, which `storm run` sets for its command. Throws a
44
+ * The run payload in `env`'s `STORM_RUN`, which a storm run sets for its command. Throws a
45
45
  * `RunPayloadError` saying what is wrong when the variable is missing or holds no valid version 2 run payload.
46
46
  */
47
47
  export declare function readRunPayload(env?: Readonly<Record<string, string | undefined>>): RunPayload;
@@ -24,13 +24,13 @@ export class RunPayloadError extends Error {
24
24
  name = "RunPayloadError";
25
25
  }
26
26
  /**
27
- * The run payload in `env`'s `STORM_RUN`, which `storm run` sets for its command. Throws a
27
+ * The run payload in `env`'s `STORM_RUN`, which a storm run sets for its command. Throws a
28
28
  * `RunPayloadError` saying what is wrong when the variable is missing or holds no valid version 2 run payload.
29
29
  */
30
30
  export function readRunPayload(env = process.env) {
31
31
  const raw = env[RUN_PAYLOAD_VARIABLE];
32
32
  if (raw === undefined || raw === "") {
33
- throw new RunPayloadError(`${RUN_PAYLOAD_VARIABLE} is not set: run this command under \`storm run\``);
33
+ throw new RunPayloadError(`${RUN_PAYLOAD_VARIABLE} is not set: run this command under \`storm vitest\` or \`storm exec\``);
34
34
  }
35
35
  let json;
36
36
  try {
@@ -39,7 +39,7 @@ export interface VercelCliOptions {
39
39
  /**
40
40
  * Hears each invocation once it has ended, or failed to start, tokens redacted, such as to print it with
41
41
  * `describeInvocation` as the test goes. What it throws is dropped. Without one, `vercelCli` prints each invocation
42
- * with `describeInvocation` to stderr in a verbose run (`storm run --verbose`) and does nothing otherwise; a
42
+ * with `describeInvocation` to stderr in a verbose run (its `--verbose`) and does nothing otherwise; a
43
43
  * listener replaces that, so `() => {}` silences it.
44
44
  */
45
45
  readonly onInvocationEnd?: (invocation: VercelInvocation) => void;
@@ -3,6 +3,6 @@ import { type VercelCli, type VercelCliOptions } from "./driver.ts";
3
3
  * A `VercelCli` for one test, running `vercel` as real processes with `PATH`, `SystemRoot` and `TEMP` from
4
4
  * `process.env` unless `hostEnv` says otherwise. It creates `<home>/global-config` and `<home>/work` first. Without an
5
5
  * `onInvocationEnd`, it prints each invocation with `describeInvocation` to stderr in a verbose run
6
- * (`storm run --verbose`, read from `process.env`'s run payload), and nothing otherwise.
6
+ * (a run's `--verbose`, read from `process.env`'s run payload), and nothing otherwise.
7
7
  */
8
8
  export declare function vercelCli(options: VercelCliOptions): Promise<VercelCli>;
@@ -5,7 +5,7 @@ import { defaultInvocationListener } from "./verbose.js";
5
5
  * A `VercelCli` for one test, running `vercel` as real processes with `PATH`, `SystemRoot` and `TEMP` from
6
6
  * `process.env` unless `hostEnv` says otherwise. It creates `<home>/global-config` and `<home>/work` first. Without an
7
7
  * `onInvocationEnd`, it prints each invocation with `describeInvocation` to stderr in a verbose run
8
- * (`storm run --verbose`, read from `process.env`'s run payload), and nothing otherwise.
8
+ * (a run's `--verbose`, read from `process.env`'s run payload), and nothing otherwise.
9
9
  */
10
10
  export function vercelCli(options) {
11
11
  const onInvocationEnd = options.onInvocationEnd ?? defaultInvocationListener(process.env, (text) => console.error(text));
@@ -1,7 +1,7 @@
1
1
  import type { VercelInvocation } from "./invocation.ts";
2
2
  /**
3
3
  * The listener `vercelCli` uses when the caller passes no `onInvocationEnd`: one that prints each invocation with
4
- * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (`storm run --verbose`), or
5
- * `undefined` outside `storm run`, in a run that isn't verbose, or when the run payload can't be read.
4
+ * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (its `--verbose`), or
5
+ * `undefined` outside a storm run, in a run that isn't verbose, or when the run payload can't be read.
6
6
  */
7
7
  export declare function defaultInvocationListener(env: Readonly<Record<string, string | undefined>>, print: (text: string) => void): ((invocation: VercelInvocation) => void) | undefined;
@@ -4,8 +4,8 @@ import { readRunPayload, RUN_PAYLOAD_VARIABLE, RunPayloadError } from "../sdk/in
4
4
  import { describeInvocation } from "./report.js";
5
5
  /**
6
6
  * The listener `vercelCli` uses when the caller passes no `onInvocationEnd`: one that prints each invocation with
7
- * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (`storm run --verbose`), or
8
- * `undefined` outside `storm run`, in a run that isn't verbose, or when the run payload can't be read.
7
+ * `describeInvocation` to `print`, when `env`'s run payload says the run is verbose (its `--verbose`), or
8
+ * `undefined` outside a storm run, in a run that isn't verbose, or when the run payload can't be read.
9
9
  */
10
10
  export function defaultInvocationListener(env, print) {
11
11
  const raw = env[RUN_PAYLOAD_VARIABLE];
@@ -25,7 +25,7 @@ export interface TestserverWorkersOptions {
25
25
  }
26
26
  /**
27
27
  * The `maxWorkers` for a testserver vitest project: `workersPerSandbox` times the number of Testserver sandboxes in
28
- * the run payload. With `STORM_RUN` unset or empty, outside `storm run`, it counts one Testserver sandbox,
28
+ * the run payload. With `STORM_RUN` unset or empty, outside a storm run, it counts one Testserver sandbox,
29
29
  * so the config still loads. Throws a `RunPayloadError` when `STORM_RUN` holds no valid run payload, and an
30
30
  * `Error` when `workersPerSandbox` is not a positive integer.
31
31
  */
@@ -36,15 +36,15 @@ export interface StormReporterOptions {
36
36
  }
37
37
  /**
38
38
  * A vitest reporter for a testserver project's config: it appends each test's final result, retries settled, to the
39
- * run payload's `testEvents` file, which `storm run` counts the tests from. It prints nothing, so list it beside
39
+ * run payload's `testEvents` file, which the run counts the tests from. It prints nothing, so list it beside
40
40
  * the reporter a person reads, `reporters: ["default", stormReporter()]`; a `--reporter` given to vitest on the
41
- * command line replaces both. Outside `storm run`, or when the run payload names no test events file, it
41
+ * command line replaces both. Outside a storm run, or when the run payload names no test events file, it
42
42
  * reports nothing, and once an append fails it drops every later result: it never fails a test.
43
43
  */
44
44
  export declare function stormReporter(options?: StormReporterOptions): StormReporter;
45
45
  /**
46
- * The reporters for a testserver project's config under `storm run`: vitest's `default`, which names each file
47
- * and its slow or failed tests as each file finishes, or under `storm run --verbose` its `verbose`, which names
46
+ * The reporters for a testserver project's config under a storm run: vitest's `default`, which names each file
47
+ * and its slow or failed tests as each file finishes, or under a run's `--verbose` its `verbose`, which names
48
48
  * each test as it finishes; and `stormReporter()`. With `STORM_RUN` unset or empty it picks `default`.
49
49
  * Throws a `RunPayloadError` when `STORM_RUN` holds no valid run payload.
50
50
  */
@@ -23,7 +23,7 @@ export const testserverConnectionRetry = {
23
23
  };
24
24
  /**
25
25
  * The `maxWorkers` for a testserver vitest project: `workersPerSandbox` times the number of Testserver sandboxes in
26
- * the run payload. With `STORM_RUN` unset or empty, outside `storm run`, it counts one Testserver sandbox,
26
+ * the run payload. With `STORM_RUN` unset or empty, outside a storm run, it counts one Testserver sandbox,
27
27
  * so the config still loads. Throws a `RunPayloadError` when `STORM_RUN` holds no valid run payload, and an
28
28
  * `Error` when `workersPerSandbox` is not a positive integer.
29
29
  */
@@ -39,17 +39,17 @@ export function testserverWorkers(options = {}) {
39
39
  }
40
40
  /**
41
41
  * A vitest reporter for a testserver project's config: it appends each test's final result, retries settled, to the
42
- * run payload's `testEvents` file, which `storm run` counts the tests from. It prints nothing, so list it beside
42
+ * run payload's `testEvents` file, which the run counts the tests from. It prints nothing, so list it beside
43
43
  * the reporter a person reads, `reporters: ["default", stormReporter()]`; a `--reporter` given to vitest on the
44
- * command line replaces both. Outside `storm run`, or when the run payload names no test events file, it
44
+ * command line replaces both. Outside a storm run, or when the run payload names no test events file, it
45
45
  * reports nothing, and once an append fails it drops every later result: it never fails a test.
46
46
  */
47
47
  export function stormReporter(options = {}) {
48
48
  return testResultReporter(options.env ?? process.env);
49
49
  }
50
50
  /**
51
- * The reporters for a testserver project's config under `storm run`: vitest's `default`, which names each file
52
- * and its slow or failed tests as each file finishes, or under `storm run --verbose` its `verbose`, which names
51
+ * The reporters for a testserver project's config under a storm run: vitest's `default`, which names each file
52
+ * and its slow or failed tests as each file finishes, or under a run's `--verbose` its `verbose`, which names
53
53
  * each test as it finishes; and `stormReporter()`. With `STORM_RUN` unset or empty it picks `default`.
54
54
  * Throws a `RunPayloadError` when `STORM_RUN` holds no valid run payload.
55
55
  */
@@ -0,0 +1,7 @@
1
+ /** Where a package's `vitest` sits under a directory. */
2
+ export declare const VITEST_BIN: string;
3
+ /**
4
+ * The directories whose `node_modules/.bin` may hold `vitest`, nearest first: `from`, then each directory above it, up
5
+ * to and including `root`. When `from` isn't `root` or inside it, up to the filesystem's root.
6
+ */
7
+ export declare function vitestSearchDirectories(from: string, root: string): readonly string[];
@@ -0,0 +1,28 @@
1
+ // Where to look for `vitest` in `node_modules/.bin`. Pure, so the live list gateway and its fake look in the same
2
+ // directories.
3
+ import { dirname, join, relative, isAbsolute } from "node:path";
4
+ /** Where a package's `vitest` sits under a directory. */
5
+ export const VITEST_BIN = join("node_modules", ".bin", "vitest");
6
+ /**
7
+ * The directories whose `node_modules/.bin` may hold `vitest`, nearest first: `from`, then each directory above it, up
8
+ * to and including `root`. When `from` isn't `root` or inside it, up to the filesystem's root.
9
+ */
10
+ export function vitestSearchDirectories(from, root) {
11
+ const inside = from === root || isInside(root, from);
12
+ const directories = [];
13
+ let directory = from;
14
+ for (;;) {
15
+ directories.push(directory);
16
+ if (inside && directory === root)
17
+ return directories;
18
+ const parent = dirname(directory);
19
+ if (parent === directory)
20
+ return directories;
21
+ directory = parent;
22
+ }
23
+ }
24
+ /** Whether `path` is inside `directory`, below it. */
25
+ function isInside(directory, path) {
26
+ const between = relative(directory, path);
27
+ return between !== "" && !between.startsWith("..") && !isAbsolute(between);
28
+ }
@@ -21,11 +21,11 @@ declare module "vitest" {
21
21
  * (`@cnc-tools/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
22
22
  * `stormTestEvents` are the adapter's own, which tests don't use.
23
23
  *
24
- * - `verbose` (per worker): whether the run is verbose, under `storm run --verbose`, from the run payload. Then
24
+ * - `verbose` (per worker): whether the run is verbose, under a run's `--verbose`, from the run payload. Then
25
25
  * `container` prints each container start and `proxy` each request as it is recorded, for passing tests too, and
26
26
  * a test's own fixture can print what it does, as the Vercel CLI driver's invocations.
27
27
  * - `testserverUrl` (per worker): this worker's Testserver sandbox, `sandboxes[(VITEST_POOL_ID - 1) % N]` from the
28
- * run payload's `resources.testserverPool`. Outside `storm run`, or with a `VITEST_POOL_ID` that isn't a
28
+ * run payload's `resources.testserverPool`. Outside a storm run, or with a `VITEST_POOL_ID` that isn't a
29
29
  * positive integer, it throws, so the test fails rather than skips.
30
30
  * - `stormFile` (per file): the adapter's own state for the file, which tests don't use: its `container`, the
31
31
  * holder of the file's container, and its `acquisitions`, the container and proxy starts still in flight. Creating
@@ -7,7 +7,7 @@ import { sandboxForWorker } from "./sandbox.js";
7
7
  import { countTests, reportedStart, testEventReporter, testEventState } from "./test-events.js";
8
8
  /**
9
9
  * The Testserver URL of this worker's Testserver sandbox, `sandboxes[(VITEST_POOL_ID - 1) % N]` of the run
10
- * payload's `resources.testserverPool`. Throws outside `storm run`, and outside a vitest worker.
10
+ * payload's `resources.testserverPool`. Throws outside a storm run, and outside a vitest worker.
11
11
  */
12
12
  function workerTestserverUrl() {
13
13
  return sandboxForWorker(readRunPayload(), process.env["VITEST_POOL_ID"]);
@@ -126,11 +126,11 @@ const fixtures = vitestTest
126
126
  * (`@cnc-tools/storm/vitest/config`), in vitest's main process. `stormEvents`, `stormFileEvents` and
127
127
  * `stormTestEvents` are the adapter's own, which tests don't use.
128
128
  *
129
- * - `verbose` (per worker): whether the run is verbose, under `storm run --verbose`, from the run payload. Then
129
+ * - `verbose` (per worker): whether the run is verbose, under a run's `--verbose`, from the run payload. Then
130
130
  * `container` prints each container start and `proxy` each request as it is recorded, for passing tests too, and
131
131
  * a test's own fixture can print what it does, as the Vercel CLI driver's invocations.
132
132
  * - `testserverUrl` (per worker): this worker's Testserver sandbox, `sandboxes[(VITEST_POOL_ID - 1) % N]` from the
133
- * run payload's `resources.testserverPool`. Outside `storm run`, or with a `VITEST_POOL_ID` that isn't a
133
+ * run payload's `resources.testserverPool`. Outside a storm run, or with a `VITEST_POOL_ID` that isn't a
134
134
  * positive integer, it throws, so the test fails rather than skips.
135
135
  * - `stormFile` (per file): the adapter's own state for the file, which tests don't use: its `container`, the
136
136
  * holder of the file's container, and its `acquisitions`, the container and proxy starts still in flight. Creating
@@ -5,19 +5,44 @@ export interface ListedTest {
5
5
  /** The absolute path of its file. */
6
6
  readonly file: string;
7
7
  }
8
- /** What to list: `vitest list --json` with `args` after it, such as a project and file filters. */
8
+ /** What to list: `vitest list` with `args`, such as a project and file filters, and `--json`. */
9
9
  export interface VitestListRequest {
10
- /** Passed after `list --json`, as `vitest run` takes them. */
10
+ /** Passed to `vitest list`, as `vitest run` takes them. */
11
11
  readonly args: readonly string[];
12
12
  /** Where vitest runs; default the current directory. */
13
13
  readonly cwd?: string;
14
+ /** The `vitest` to start, such as the absolute path `findVitest` found; default `vitest` from `PATH`. */
15
+ readonly executable?: string;
14
16
  /** How long the listing may take before it is killed. */
15
17
  readonly timeoutMs: number;
18
+ /** Stops the listing when it aborts, before it starts or while it runs: the listing is `canceled`. */
19
+ readonly signal?: AbortSignal;
16
20
  }
21
+ /** Where to look for `vitest`: in `node_modules/.bin` of `from` and of each directory above it, up to `root`. */
22
+ export interface FindVitestRequest {
23
+ /** The directory vitest runs in, an absolute path. */
24
+ readonly from: string;
25
+ /**
26
+ * The last directory to look in, an absolute path: the repository's root, or the filesystem's root outside a
27
+ * repository. When `from` isn't inside it, the search goes on up to the filesystem's root.
28
+ */
29
+ readonly root: string;
30
+ }
31
+ /**
32
+ * The `vitest` found nearest `from`, as an absolute path to its `node_modules/.bin/vitest`; or, when no directory has
33
+ * one, every directory looked in, nearest first (`vitestSearchDirectories`).
34
+ */
35
+ export type FindVitestResult = {
36
+ readonly ok: true;
37
+ readonly path: string;
38
+ } | {
39
+ readonly ok: false;
40
+ readonly searched: readonly string[];
41
+ };
17
42
  /**
18
- * Why the tests couldn't be listed: `vitest` couldn't be started (not on `PATH`, or no such `cwd`), it didn't finish
19
- * within `timeoutMs`, it exited other than 0 (with the last line of its stderr that isn't blank or a stack frame, empty
20
- * when there is none), or its output wasn't a list of tests.
43
+ * Why the tests couldn't be listed: `vitest` couldn't be started (not on `PATH` or not found, or no such `cwd`), it
44
+ * didn't finish within `timeoutMs`, it exited other than 0 (with the last line of its stderr that isn't blank or a
45
+ * stack frame, empty when there is none), its output wasn't a list of tests, or the request's `signal` stopped it.
21
46
  */
22
47
  export type VitestListFailure = {
23
48
  readonly kind: "start-failed";
@@ -33,6 +58,8 @@ export type VitestListFailure = {
33
58
  } | {
34
59
  readonly kind: "unreadable-output";
35
60
  readonly message: string;
61
+ } | {
62
+ readonly kind: "canceled";
36
63
  };
37
64
  export type VitestListResult = {
38
65
  readonly ok: true;
@@ -41,7 +68,11 @@ export type VitestListResult = {
41
68
  readonly ok: false;
42
69
  readonly failure: VitestListFailure;
43
70
  };
44
- /** Lists the tests a `vitest run` with the same arguments would run, without running them. */
45
71
  export interface VitestListGateway {
72
+ /** Lists the tests a `vitest run` with the same arguments would run, without running them. */
46
73
  listTests(request: VitestListRequest): Promise<VitestListResult>;
74
+ /**
75
+ * Finds the `vitest` a package's scripts would run: the nearest `node_modules/.bin/vitest` from `from` up to `root`.
76
+ */
77
+ findVitest(request: FindVitestRequest): Promise<FindVitestResult>;
47
78
  }
@@ -1,3 +1,4 @@
1
- // The Vitest adapter's gateway: listing the tests a `vitest run` would run, before any Testserver sandbox is leased.
2
- // The live gateway is `live/list-gateway.ts`; the fake is `test/fakes/vitest/list-gateway.ts`.
1
+ // The Vitest adapter's gateway: finding `vitest` in `node_modules/.bin`, and listing the tests a `vitest run` would
2
+ // run, before any Testserver sandbox is leased. The live gateway is `live/list-gateway.ts`; the fake is
3
+ // `test/fakes/vitest/list-gateway.ts`.
3
4
  export {};
@@ -1,7 +1,11 @@
1
1
  import type { VitestListGateway } from "../gateways.ts";
2
2
  /**
3
- * The live list gateway: spawns `vitest list --json <args>` from `PATH`, no shell, in `cwd`, with stdin ignored,
4
- * and kills it after `timeoutMs` (`AbortSignal.timeout`). An `error` before the process exits is a start failure,
5
- * unless the timeout caused it.
3
+ * The live list gateway. `listTests` spawns `vitest list <args> --json` (`listArgv`), the request's `executable` or
4
+ * `vitest` from `PATH`, no shell, in `cwd`, with stdin ignored. It sends SIGTERM after `timeoutMs`
5
+ * (`AbortSignal.timeout`), or once the request's `signal` aborts, then waits for the process to exit and answers
6
+ * `timed-out` or `canceled`, `canceled` when the request's `signal` aborted. It waits for the exit, not for the pipes
7
+ * to close, since a process `vitest` left behind could hold them open. Any other `error` is a start failure, answered
8
+ * at once, since no process started. `findVitest` answers the first `node_modules/.bin/vitest` this process may
9
+ * execute, in `vitestSearchDirectories` order.
6
10
  */
7
11
  export declare const liveVitestListGateway: VitestListGateway;
@@ -1,11 +1,33 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { constants } from "node:fs";
3
+ import { access } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { VITEST_BIN, vitestSearchDirectories } from "../find-vitest.js";
2
6
  import { readVitestList } from "../list-output.js";
3
7
  /**
4
- * The live list gateway: spawns `vitest list --json <args>` from `PATH`, no shell, in `cwd`, with stdin ignored,
5
- * and kills it after `timeoutMs` (`AbortSignal.timeout`). An `error` before the process exits is a start failure,
6
- * unless the timeout caused it.
8
+ * The live list gateway. `listTests` spawns `vitest list <args> --json` (`listArgv`), the request's `executable` or
9
+ * `vitest` from `PATH`, no shell, in `cwd`, with stdin ignored. It sends SIGTERM after `timeoutMs`
10
+ * (`AbortSignal.timeout`), or once the request's `signal` aborts, then waits for the process to exit and answers
11
+ * `timed-out` or `canceled`, `canceled` when the request's `signal` aborted. It waits for the exit, not for the pipes
12
+ * to close, since a process `vitest` left behind could hold them open. Any other `error` is a start failure, answered
13
+ * at once, since no process started. `findVitest` answers the first `node_modules/.bin/vitest` this process may
14
+ * execute, in `vitestSearchDirectories` order.
7
15
  */
8
16
  export const liveVitestListGateway = {
17
+ async findVitest({ from, root }) {
18
+ const searched = vitestSearchDirectories(from, root);
19
+ for (const directory of searched) {
20
+ const path = join(directory, VITEST_BIN);
21
+ try {
22
+ await access(path, constants.X_OK);
23
+ return { ok: true, path };
24
+ }
25
+ catch {
26
+ // Not there, or not executable: look further up.
27
+ }
28
+ }
29
+ return { ok: false, searched };
30
+ },
9
31
  listTests(request) {
10
32
  return new Promise((resolve) => {
11
33
  let settled = false;
@@ -15,11 +37,14 @@ export const liveVitestListGateway = {
15
37
  settled = true;
16
38
  resolve(result);
17
39
  };
18
- const child = spawn("vitest", ["list", "--json", ...request.args], {
40
+ const timeout = AbortSignal.timeout(request.timeoutMs);
41
+ const child = spawn(request.executable ?? "vitest", listArgv(request.args), {
19
42
  ...(request.cwd === undefined ? {} : { cwd: request.cwd }),
20
43
  stdio: ["ignore", "pipe", "pipe"],
21
- signal: AbortSignal.timeout(request.timeoutMs),
44
+ signal: request.signal === undefined ? timeout : AbortSignal.any([timeout, request.signal]),
22
45
  });
46
+ // Why the listing was stopped, once the abort killed the process: answered when it has exited.
47
+ let stopped;
23
48
  let stdout = "";
24
49
  let stderr = "";
25
50
  child.stdout.setEncoding("utf8").on("data", (chunk) => {
@@ -29,11 +54,24 @@ export const liveVitestListGateway = {
29
54
  stderr += chunk;
30
55
  });
31
56
  child.on("error", (error) => {
32
- settle(error.name === "AbortError"
33
- ? { ok: false, failure: { kind: "timed-out", timeoutMs: request.timeoutMs } }
34
- : { ok: false, failure: { kind: "start-failed", message: error.message } });
57
+ if (error.name !== "AbortError") {
58
+ settle({ ok: false, failure: { kind: "start-failed", message: error.message } });
59
+ return;
60
+ }
61
+ stopped =
62
+ request.signal?.aborted === true ? { kind: "canceled" } : { kind: "timed-out", timeoutMs: request.timeoutMs };
63
+ if (child.exitCode !== null || child.signalCode !== null)
64
+ settle({ ok: false, failure: stopped });
65
+ });
66
+ child.on("exit", () => {
67
+ if (stopped !== undefined)
68
+ settle({ ok: false, failure: stopped });
35
69
  });
36
70
  child.on("close", (exitCode, signal) => {
71
+ if (stopped !== undefined) {
72
+ settle({ ok: false, failure: stopped });
73
+ return;
74
+ }
37
75
  if (exitCode !== 0) {
38
76
  settle({ ok: false, failure: { kind: "exited", exitCode, signal, lastStderrLine: lastLine(stderr) } });
39
77
  return;
@@ -58,3 +96,12 @@ function lastLine(text) {
58
96
  .map((line) => line.trim())
59
97
  .findLast((line) => line !== "" && !/^at\s/.test(line)) ?? "");
60
98
  }
99
+ /**
100
+ * `vitest list`'s arguments: `args`, with `--json` after them but before a `--` among them. vitest's `--json` takes an
101
+ * optional path, so `vitest list --json test/a.test.ts` would write the list over `test/a.test.ts`; after the
102
+ * arguments, it takes none, and the list goes to stdout.
103
+ */
104
+ function listArgv(args) {
105
+ const end = args.indexOf("--");
106
+ return end === -1 ? ["list", ...args, "--json"] : ["list", ...args.slice(0, end), "--json", ...args.slice(end)];
107
+ }