@cnc-tools/storm 0.13.0 → 0.14.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 (129) hide show
  1. package/dist/application.js +5 -1
  2. package/dist/bin/storm.js +6 -2
  3. package/dist/build-info.js +1 -1
  4. package/dist/chunks/{chunk-N7E6DAUE.js → chunk-27P2QSIM.js} +1 -1
  5. package/dist/chunks/{chunk-ZDJLKF2G.js → chunk-5ED3IDUJ.js} +7 -4
  6. package/dist/chunks/{chunk-6EQKA7LI.js → chunk-5TMHYH7G.js} +1 -1
  7. package/dist/chunks/{chunk-AX4EQZUS.js → chunk-BFLYGMG3.js} +12 -7
  8. package/dist/chunks/{chunk-LQKNI3EG.js → chunk-BRUIATTR.js} +6 -6
  9. package/dist/chunks/{chunk-DOFB2ACU.js → chunk-HOKDKP5A.js} +1 -1
  10. package/dist/chunks/{chunk-EGNP3S6C.js → chunk-IVRRGGCD.js} +60 -20
  11. package/dist/chunks/{chunk-RTILVSYQ.js → chunk-QBR5VHJ7.js} +1 -1
  12. package/dist/chunks/{chunk-YT5OROR7.js → chunk-RA4L2ACU.js} +12 -2
  13. package/dist/chunks/{chunk-YGS5VRQT.js → chunk-RKONDLPS.js} +8 -5
  14. package/dist/chunks/{chunk-IYM44FUX.js → chunk-UC6DULWY.js} +2 -2
  15. package/dist/chunks/{chunk-2NZXL6OH.js → chunk-XPCUINWS.js} +1 -1
  16. package/dist/chunks/{chunk-Q4TKRILH.js → chunk-YBPTMJUM.js} +98 -21
  17. package/dist/chunks/{chunk-5UMJNVKT.js → chunk-Z5OXOZD3.js} +125 -83
  18. package/dist/chunks/{chunk-X4WBJIOF.js → chunk-ZH5R7W4A.js} +1 -1
  19. package/dist/chunks/{live-app-QFHS54SX.js → live-app-FBVWUUMT.js} +7 -7
  20. package/dist/commands/exec/command.d.ts +2 -0
  21. package/dist/commands/exec/command.js +15 -41
  22. package/dist/commands/exec/define-run-command.d.ts +17 -10
  23. package/dist/commands/exec/define-run-command.js +48 -15
  24. package/dist/commands/exec/driver-plan.d.ts +24 -16
  25. package/dist/commands/exec/driver-plan.js +34 -15
  26. package/dist/commands/exec/driver-refusals.js +7 -6
  27. package/dist/commands/exec/exec-words.d.ts +1 -1
  28. package/dist/commands/exec/exec-words.js +8 -2
  29. package/dist/commands/exec/final-results.d.ts +39 -0
  30. package/dist/commands/exec/final-results.js +29 -0
  31. package/dist/commands/exec/metadata.js +1 -1
  32. package/dist/commands/exec/outcomes.d.ts +13 -3
  33. package/dist/commands/exec/outcomes.js +21 -4
  34. package/dist/commands/exec/plan-run.d.ts +11 -3
  35. package/dist/commands/exec/plan-run.js +3 -2
  36. package/dist/commands/exec/run-command.d.ts +1 -1
  37. package/dist/commands/exec/run-command.js +27 -5
  38. package/dist/commands/exec/test-plan.d.ts +2 -1
  39. package/dist/commands/exec/test-plan.js +13 -4
  40. package/dist/commands/exec/tests-summary.d.ts +2 -2
  41. package/dist/commands/exec/worker-chart.d.ts +1 -1
  42. package/dist/commands/playwright/command.d.ts +10 -7
  43. package/dist/commands/playwright/command.js +14 -14
  44. package/dist/commands/playwright/metadata.js +2 -2
  45. package/dist/commands/runs/list/command.js +6 -6
  46. package/dist/commands/runs/logs/command.js +6 -6
  47. package/dist/commands/runs/show/command.d.ts +2 -2
  48. package/dist/commands/runs/show/command.js +11 -11
  49. package/dist/commands/runs/show/outcomes.d.ts +1 -1
  50. package/dist/commands/snapshots/build/command.js +12 -12
  51. package/dist/commands/snapshots/list/command.js +9 -9
  52. package/dist/commands/vitest/command.d.ts +12 -8
  53. package/dist/commands/vitest/command.js +14 -14
  54. package/dist/commands/vitest/metadata.js +2 -2
  55. package/dist/config/resolve.d.ts +1 -1
  56. package/dist/config/resolve.js +2 -1
  57. package/dist/config/schema.d.ts +8 -0
  58. package/dist/config/schema.js +5 -4
  59. package/dist/extensions/playwright/driver.js +17 -10
  60. package/dist/extensions/testserver/commands/pool/create/command.js +4 -4
  61. package/dist/extensions/testserver/commands/pool/list/command.js +2 -2
  62. package/dist/extensions/testserver/definition.d.ts +1 -1
  63. package/dist/extensions/testserver/extension.d.ts +1 -1
  64. package/dist/extensions/testserver/options/rules.d.ts +3 -3
  65. package/dist/extensions/testserver/options/rules.js +5 -5
  66. package/dist/extensions/testserver/resource.d.ts +1 -1
  67. package/dist/extensions/testserver/vercel-cli/index.d.ts +1 -0
  68. package/dist/extensions/testserver/vercel-cli/index.js +1 -0
  69. package/dist/extensions/testserver/vercel-cli/report.js +5 -2
  70. package/dist/extensions/testserver/vercel-cli/session-id.d.ts +8 -0
  71. package/dist/extensions/testserver/vercel-cli/session-id.js +16 -0
  72. package/dist/extensions/testserver/vitest/config.d.ts +2 -2
  73. package/dist/extensions/testserver/vitest/config.js +2 -2
  74. package/dist/extensions/testserver/vitest/container-scope.d.ts +25 -16
  75. package/dist/extensions/testserver/vitest/container-scope.js +32 -13
  76. package/dist/extensions/testserver/vitest/diagnostics.d.ts +5 -4
  77. package/dist/extensions/testserver/vitest/diagnostics.js +15 -8
  78. package/dist/extensions/testserver/vitest/fixtures.d.ts +10 -1
  79. package/dist/extensions/testserver/vitest/fixtures.js +36 -10
  80. package/dist/extensions/testserver/vitest/types.d.ts +9 -0
  81. package/dist/extensions/vitest/driver.js +28 -14
  82. package/dist/extensions/vitest/plan/gateways.d.ts +28 -5
  83. package/dist/extensions/vitest/plan/gateways.js +2 -2
  84. package/dist/extensions/vitest/plan/list-output.d.ts +5 -0
  85. package/dist/extensions/vitest/plan/list-output.js +23 -9
  86. package/dist/extensions/vitest/plan/live/list-gateway.d.ts +3 -2
  87. package/dist/extensions/vitest/plan/live/list-gateway.js +77 -64
  88. package/dist/extensions/vitest/plan/plan-over.d.ts +19 -7
  89. package/dist/extensions/vitest/plan/plan-over.js +18 -7
  90. package/dist/extensions/vitest/plan/plan.d.ts +14 -5
  91. package/dist/extensions/vitest/plan/plan.js +23 -9
  92. package/dist/extensions.d.ts +2 -2
  93. package/dist/run-directory/plan.d.ts +3 -2
  94. package/dist/run-directory/plan.js +6 -3
  95. package/dist/run-directory/run-record.d.ts +4 -3
  96. package/dist/runner/recipe.d.ts +5 -1
  97. package/dist/runner/sandboxed-command.d.ts +5 -3
  98. package/dist/runner/sandboxed-command.js +10 -4
  99. package/dist/sdk/extension/driver.d.ts +32 -6
  100. package/dist/sdk/extension/driver.js +12 -2
  101. package/dist/sdk/extension/index.d.ts +1 -1
  102. package/dist/sdk/extension/index.js +2 -1
  103. package/dist/sdk/extension/resource-definition.d.ts +6 -5
  104. package/dist/vendor/testserver-sdk/container/api-request.d.ts +2 -3
  105. package/dist/vendor/testserver-sdk/container/api-request.js +2 -3
  106. package/dist/vendor/testserver-sdk/container/container.d.ts +12 -2
  107. package/dist/vendor/testserver-sdk/container/container.js +10 -7
  108. package/dist/vendor/testserver-sdk/container/recorder.d.ts +29 -7
  109. package/dist/vendor/testserver-sdk/container/recorder.js +26 -14
  110. package/dist/vendor/testserver-sdk/index.d.ts +1 -1
  111. package/dist/vendor/testserver-sdk/index.js +1 -1
  112. package/dist/vendor/testserver-sdk/proxy/exchange.d.ts +24 -5
  113. package/dist/vendor/testserver-sdk/proxy/exchange.js +43 -25
  114. package/dist/vendor/testserver-sdk/proxy/faulted-exchange.js +15 -10
  115. package/dist/vendor/testserver-sdk/proxy/faults.d.ts +6 -5
  116. package/dist/vendor/testserver-sdk/proxy/proxy.d.ts +10 -1
  117. package/dist/vendor/testserver-sdk/proxy/proxy.js +5 -3
  118. package/dist/vendor/testserver-sdk/proxy/records.d.ts +17 -17
  119. package/dist/vendor/testserver-sdk/proxy/records.js +18 -17
  120. package/dist/vendor/testserver-sdk/records/body.d.ts +7 -9
  121. package/dist/vendor/testserver-sdk/records/body.js +10 -15
  122. package/dist/vendor/testserver-sdk/records/headers.d.ts +79 -0
  123. package/dist/vendor/testserver-sdk/records/headers.js +162 -0
  124. package/dist/vendor/testserver-sdk/records/index.d.ts +2 -1
  125. package/dist/vendor/testserver-sdk/records/index.js +4 -2
  126. package/dist/vendor/testserver-sdk/records/records.d.ts +19 -10
  127. package/package.json +5 -4
  128. package/skills/overview.md +5 -5
  129. package/skills/testserver-builds.md +0 -82
@@ -3,11 +3,29 @@ import { activityCounts, activityFailed, activitySince, containerFailureReport,
3
3
  import { acquireOwned } from "../../../vitest/index.js";
4
4
  /** The default container scope: a test file's tests share one container. */
5
5
  export const CONTAINER_SCOPE = "file";
6
+ /** Why a container started for `current` can't serve a test that needs `wanted`, or `undefined` when it can. */
7
+ function replacedFor(current, wanted) {
8
+ const flags = current.featureFlags !== wanted.featureFlags;
9
+ const headers = current.recordHeaders !== wanted.recordHeaders;
10
+ if (flags && headers)
11
+ return "options";
12
+ if (flags)
13
+ return "feature-flags";
14
+ if (headers)
15
+ return "record-headers";
16
+ return undefined;
17
+ }
18
+ /** What differs between a test and the file's container, for the error of an end that failed to replace it. */
19
+ const DIFFERENT = {
20
+ "feature-flags": "different feature flags",
21
+ "record-headers": "a different recordHeaders list",
22
+ options: "different feature flags and a different recordHeaders list",
23
+ };
6
24
  /**
7
25
  * A test file's container in `'file'` scope. It starts lazily, when the first test asks for it; concurrent
8
- * `acquire` calls with the same feature flags key share one start, and a failed start leaves nothing behind, so the
9
- * next `acquire` starts again. The container remembers the feature flags key it started with: a test with a
10
- * different one gets a new container, which replaces it.
26
+ * `acquire` calls with the same `ContainerKey` share one start, and a failed start leaves nothing behind, so the
27
+ * next `acquire` starts again. The container remembers the key it started with: a test with a different one gets a
28
+ * new container, which replaces it.
11
29
  */
12
30
  export class FileContainer {
13
31
  #current;
@@ -18,8 +36,8 @@ export class FileContainer {
18
36
  return this.#current?.container;
19
37
  }
20
38
  /**
21
- * The file's container for a test whose feature flags key is `key` (`featureFlagsKey`): the running one, or the
22
- * one starting, when either has the same key, or one `start` starts. A running container with a different key is
39
+ * The file's container for a test whose container key is `key`: the running one, or the one starting, when either
40
+ * has the same key, or one `start` starts. A running container with a different key is
23
41
  * forgotten and ended first, and the new one replaces it; when that end fails, rejects saying so, leaving no
24
42
  * container. A start in flight with a different key is waited for, its failure ignored, then treated the same way.
25
43
  * Throws after `close`.
@@ -29,7 +47,8 @@ export class FileContainer {
29
47
  return Promise.reject(new Error("the test file's container was already closed"));
30
48
  const current = this.#current;
31
49
  if (current !== undefined) {
32
- if (current.key === key)
50
+ const replacing = replacedFor(current.key, key);
51
+ if (replacing === undefined)
33
52
  return Promise.resolve({ container: current.container, origin: "reused" });
34
53
  this.#current = undefined;
35
54
  return this.#begin(key, true, async () => {
@@ -37,14 +56,14 @@ export class FileContainer {
37
56
  await current.container.end();
38
57
  }
39
58
  catch (error) {
40
- throw new Error(`ending the file's container ${current.container.testId} to replace it for a test with different feature flags failed: ${messageOf(error)}`, { cause: error });
59
+ throw new Error(`ending the file's container ${current.container.testId} to replace it for a test with ${DIFFERENT[replacing]} failed: ${messageOf(error)}`, { cause: error });
41
60
  }
42
- return start("feature-flags");
61
+ return start(replacing);
43
62
  });
44
63
  }
45
64
  const starting = this.#starting;
46
65
  if (starting !== undefined) {
47
- if (starting.key === key)
66
+ if (replacedFor(starting.key, key) === undefined)
48
67
  return starting.promise.then((container) => ({ container, origin: "new" }));
49
68
  return starting.promise.then(() => this.acquire(start, key), () => this.acquire(start, key));
50
69
  }
@@ -52,7 +71,7 @@ export class FileContainer {
52
71
  }
53
72
  /**
54
73
  * Replaces `stopped`, the file's container, which Testserver has stopped, with one `start` starts for a test whose
55
- * feature flags key is `key`: forgets it, ends it (Testserver answers the end of a stopped container's test id),
74
+ * container key is `key`: forgets it, ends it (Testserver answers the end of a stopped container's test id),
56
75
  * then starts the new one. When the end fails, rejects saying so, leaving no container. Throws after `close`.
57
76
  */
58
77
  replaceStopped(stopped, start, key) {
@@ -114,7 +133,7 @@ export class FileContainer {
114
133
  * container log read there, before the container ends; one that fails later is reported without it.
115
134
  *
116
135
  * In `'file'` scope, hands the test the file's container, starting it if need be, or replacing it when its feature
117
- * flags differ from the test's. A test that aborts while it is starting never gets it, but the container stays the
136
+ * flags or its `recordHeaders` list differ from the test's. A test that aborts while it is starting never gets it, but the container stays the
118
137
  * file's, for its next test. A test handed a container an earlier test used notes its container log's last record, so
119
138
  * its report can print only the records after it. When that note finds Testserver has stopped the container
120
139
  * (`container-stopped`), as its idle eviction does between tests, the test gets a new container in its place, before
@@ -145,14 +164,14 @@ export async function provideContainer(request) {
145
164
  'use test.override({ containerScope: "test" }) in the file or describe that runs tests concurrently');
146
165
  }
147
166
  const { fileContainer } = request;
148
- const acquired = await fileContainer.acquire(request.startShared, request.featureFlagsKey);
167
+ const acquired = await fileContainer.acquire(request.startShared, request.containerKey);
149
168
  if (signal.aborted)
150
169
  throw signal.reason;
151
170
  const noted = acquired.origin === "reused" ? await noteLog(acquired.container) : NEW;
152
171
  if (signal.aborted)
153
172
  throw signal.reason;
154
173
  const replaced = noted.kind === "stopped"
155
- ? await fileContainer.replaceStopped(acquired.container, request.startShared, request.featureFlagsKey)
174
+ ? await fileContainer.replaceStopped(acquired.container, request.startShared, request.containerKey)
156
175
  : undefined;
157
176
  if (signal.aborted)
158
177
  throw signal.reason;
@@ -1,4 +1,5 @@
1
1
  import { type ApiRequestRecord, type ContainerLogRecord, type ExternalCallRecord, type FactoryCall, type FeatureFlags, type FaultHandle, type RecordedBody, type ProxyRequestRecord, type ServiceWarmup, type SetupCall } from "../../../vendor/testserver-sdk/index.js";
2
+ import type { ReplacedFor } from "./container-scope.ts";
2
3
  /** The most characters of one body, input, response or container log line a failure report prints. */
3
4
  export declare const BODY_REPORT_CHARS = 1000;
4
5
  /** The most container log records a failure report prints, the last ones. */
@@ -8,8 +9,8 @@ export type Redact = (text: string) => string;
8
9
  /** A request record of any kind, as one line describes it. */
9
10
  type RequestLine = ProxyRequestRecord | ApiRequestRecord | ExternalCallRecord;
10
11
  /**
11
- * One request record as a line: its method, URL as sent, result, whether it carried `authorization`, duration and
12
- * any session id, such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
12
+ * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
13
+ * duration and any `vercel` CLI session id (both read from its `requestHeaders`), such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
13
14
  * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
14
15
  * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
15
16
  * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
@@ -149,7 +150,7 @@ export declare function proxyRequestReport(testId: string, request: ProxyRequest
149
150
  export declare function describeWarmup(warmup: ServiceWarmup, redact: Redact): string;
150
151
  /**
151
152
  * What a verbose run prints once a container has started: what it is for, whether it replaced the file's container,
152
- * because the feature flags differ or because Testserver had stopped it, how long it took, how many feature flags it
153
+ * because the feature flags, the `recordHeaders` lists, or both differ, or because Testserver had stopped it, how long it took, how many feature flags it
153
154
  * has, any warmup after it with the services that failed, and its test id, such as `storm: started a container for
154
155
  * the file a.test.ts in 812ms, 1 feature flag, warmed 3 services in 2140ms (1 failed: api-projects), test id ts-…`.
155
156
  */
@@ -160,7 +161,7 @@ export declare function containerStartReport(start: {
160
161
  readonly testId: string;
161
162
  readonly featureFlags?: FeatureFlags;
162
163
  /** Why it replaced the file's container, when it did. */
163
- readonly replaced?: "feature-flags" | "stopped";
164
+ readonly replaced?: ReplacedFor;
164
165
  readonly warmup?: {
165
166
  readonly ms: number;
166
167
  readonly warmup: ServiceWarmup;
@@ -1,11 +1,12 @@
1
1
  import { describeFailure, FEATURE_FLAG_CLIENTS, REDACTED, redactTokenFields, TestserverCallError, } from "../../../vendor/testserver-sdk/index.js";
2
+ import { vercelCliSessionId } from "../vercel-cli/session-id.js";
2
3
  /** The most characters of one body, input, response or container log line a failure report prints. */
3
4
  export const BODY_REPORT_CHARS = 1000;
4
5
  /** The most container log records a failure report prints, the last ones. */
5
6
  export const LOG_REPORT_RECORDS = 50;
6
7
  /**
7
- * One request record as a line: its method, URL as sent, result, whether it carried `authorization`, duration and
8
- * any session id, such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
8
+ * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
9
+ * duration and any `vercel` CLI session id (both read from its `requestHeaders`), such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
9
10
  * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
10
11
  * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
11
12
  * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
@@ -22,8 +23,9 @@ export function describeRequest(request) {
22
23
  : request.failure === undefined
23
24
  ? `${request.status}, then failed (${request.error})`
24
25
  : `${request.status} (${request.error})`;
25
- const authorization = request.authorization ? "authorization sent" : "no authorization";
26
- const session = !("sessionId" in request) || request.sessionId === undefined ? "" : `, session ${request.sessionId}`;
26
+ const authorization = "authorization" in request.requestHeaders ? "authorization sent" : "no authorization";
27
+ const sessionId = vercelCliSessionId(request.requestHeaders);
28
+ const session = sessionId === undefined ? "" : `, session ${sessionId}`;
27
29
  const fault = "fault" in request && request.fault !== undefined ? ` ${faultTag(request.fault)}` : "";
28
30
  const external = "externalId" in request ? `external ${request.externalId} ` : "";
29
31
  return `${external}${request.method} ${request.url} → ${result}${fault}, ${authorization}, ${Math.round(request.durationMs)}ms${session}`;
@@ -317,20 +319,25 @@ export function describeWarmup(warmup, redact) {
317
319
  }
318
320
  /**
319
321
  * What a verbose run prints once a container has started: what it is for, whether it replaced the file's container,
320
- * because the feature flags differ or because Testserver had stopped it, how long it took, how many feature flags it
322
+ * because the feature flags, the `recordHeaders` lists, or both differ, or because Testserver had stopped it, how long it took, how many feature flags it
321
323
  * has, any warmup after it with the services that failed, and its test id, such as `storm: started a container for
322
324
  * the file a.test.ts in 812ms, 1 feature flag, warmed 3 services in 2140ms (1 failed: api-projects), test id ts-…`.
323
325
  */
324
326
  export function containerStartReport(start) {
325
327
  const what = start.scope === "file" ? `the file ${start.name}` : `the test ${JSON.stringify(start.name)}`;
326
- const replacing = start.replaced === undefined
327
- ? ""
328
- : `, replacing the file's container (${start.replaced === "stopped" ? "Testserver had stopped it" : "feature flags differ"}),`;
328
+ const replacing = start.replaced === undefined ? "" : `, replacing the file's container (${REPLACED_BECAUSE[start.replaced]}),`;
329
329
  const count = countFeatureFlags(start.featureFlags ?? {});
330
330
  const flags = count === 0 ? "" : `, ${count} feature ${count === 1 ? "flag" : "flags"}`;
331
331
  const warmed = start.warmup === undefined ? "" : `, ${describeWarmed(start.warmup.warmup, start.warmup.ms)}`;
332
332
  return `storm: started a container for ${what}${replacing} in ${Math.round(start.ms)}ms${flags}${warmed}, test id ${start.testId}`;
333
333
  }
334
+ /** Why a container start replaced the file's container, as `containerStartReport` says it. */
335
+ const REPLACED_BECAUSE = {
336
+ "feature-flags": "feature flags differ",
337
+ "record-headers": "recordHeaders differ",
338
+ options: "feature flags and recordHeaders differ",
339
+ stopped: "Testserver had stopped it",
340
+ };
334
341
  /** `warmed 3 services in 2140ms`, with `(1 failed: api-projects)` when any failed. */
335
342
  function describeWarmed(warmup, ms) {
336
343
  const failed = warmup.services.flatMap((service) => (service.ok ? [] : [service.serviceId]));
@@ -42,6 +42,14 @@ declare module "vitest" {
42
42
  * set before any service starts. A suite sets it on its own `test` with `.override("featureFlags", {...})`, a file
43
43
  * or `describe` with `test.override({ featureFlags })`; a value replaces the whole object. In `'file'` scope, a
44
44
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
45
+ * - `recordHeaders`: the headers whose values the container's and the proxy's records show as sent besides the
46
+ * SDK's defaults (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`, by default none. Every other header's value reads `<redacted>`, but `authorization`,
47
+ * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). The proxy's
48
+ * records also show `x-vercel-cli-session-id`, the Vercel CLI invoker's session id. A suite sets it on its own
49
+ * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
50
+ * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
51
+ * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
52
+ * any container is acquired.
45
53
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
46
54
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
47
55
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -51,7 +59,8 @@ declare module "vitest" {
51
59
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
52
60
  * container, its test id.
53
61
  * A retry of a test whose container failed to start starts one again, once: Vitest before 5.0.4 sets no fixture up
54
- * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container.
62
+ * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container. Vitest
63
+ * 5.0.4 and later start one again in each retry.
55
64
  * - `proxy`: a proxy adding `container`'s test id, per test, closed after it. Once closed, its cleanup fails the
56
65
  * test when a fault rule forwarded a request and Testserver failed (`fault.upstream.error`), or Testserver refused a
57
66
  * request because it had stopped the container; a rule with hits left doesn't.
@@ -1,15 +1,18 @@
1
1
  import { test as vitestTest } from "vitest";
2
2
  import { readRunPayload } from "../../../sdk/index.js";
3
- import { featureFlagsKey, startContainer, startProxy, } from "../../../vendor/testserver-sdk/index.js";
3
+ import { featureFlagsKey, recordHeadersKey, startContainer, startProxy, } from "../../../vendor/testserver-sdk/index.js";
4
4
  import { CONTAINER_SCOPE, closeFile, FileContainer, provideContainer, warmNewContainer, } from "./container-scope.js";
5
5
  import { containerStartReport, proxyFailureReport, proxyRequestReport, proxyTestserverFailure } from "./diagnostics.js";
6
6
  import { workerTestserverUrl } from "./worker-sandbox.js";
7
7
  import { acquireOwned, Acquisitions, countTests, testEventReporter, testEventState } from "../../../vitest/index.js";
8
8
  import { reportedStart } from "./container-start.js";
9
+ import { VERCEL_CLI_SESSION_ID_HEADER } from "../vercel-cli/session-id.js";
9
10
  /** The default `warmServices`: no service is warmed. */
10
11
  const NO_SERVICES = [];
11
12
  /** The default `featureFlags`: none. */
12
13
  const NO_FEATURE_FLAGS = {};
14
+ /** The default `recordHeaders`: none beyond the SDK's defaults, so records show every other header's value as `<redacted>`. */
15
+ const NO_RECORD_HEADERS = [];
13
16
  /**
14
17
  * `container`, the `container` fixture's value as another fixture reads it, or an error when there is none. Vitest
15
18
  * before 5.0.4 never sets up again a test's fixture whose setup threw, and hands its dependents `undefined` in every
@@ -71,15 +74,22 @@ const fixtures = vitestTest
71
74
  .extend("containerScope", CONTAINER_SCOPE)
72
75
  .extend("warmServices", NO_SERVICES)
73
76
  .extend("featureFlags", NO_FEATURE_FLAGS)
77
+ .extend("recordHeaders", NO_RECORD_HEADERS)
74
78
  // How the test's container is set up, for the fixture that hands it `onCleanup` (`stormContainer`, or `container`
75
79
  // in its place). Setting this up starts nothing and never throws.
76
- .extend("stormContainerSetup", ({ containerScope, warmServices, featureFlags, stormFile, stormTestserverFailure, stormEvents, testserverUrl, verbose, task, signal, onTestFailed, }) => async (onCleanup) => {
77
- // Starts a container labeled `name` with `featureFlags`, then warms `warmServices`, both the start's test's, in
78
- // it, reporting both as one container start. Under a verbose run, each container start prints as it ends, for
80
+ .extend("stormContainerSetup", ({ containerScope, warmServices, featureFlags, recordHeaders, stormFile, stormTestserverFailure, stormEvents, testserverUrl, verbose, task, signal, onTestFailed, }) => async (onCleanup) => {
81
+ // Checked first, in either scope, so a bad `featureFlags` or `recordHeaders` fails the test with its
82
+ // `TypeError` even when the file's container is already running and the test would reuse it.
83
+ const containerKey = {
84
+ featureFlags: featureFlagsKey(featureFlags),
85
+ recordHeaders: recordHeadersKey(recordHeaders),
86
+ };
87
+ // Starts a container labeled `name` with `featureFlags` and `recordHeaders`, then warms `warmServices` in it,
88
+ // each the start's test's, reporting the start and the warmup as one container start. Under a verbose run, each container start prints as it ends, for
79
89
  // passing tests too, saying when it replaced the file's container and why.
80
90
  const startWarmed = async (scope, name, replacing) => {
81
91
  const warm = warmServices.length === 0 ? undefined : (started) => warmNewContainer(started, warmServices);
82
- const started = await reportedStart(stormEvents, task.file.name, () => startContainer({ testserverUrl, name, featureFlags }), warm);
92
+ const started = await reportedStart(stormEvents, task.file.name, () => startContainer({ testserverUrl, name, featureFlags, recordHeaders }), warm);
83
93
  if (verbose) {
84
94
  console.error(containerStartReport({
85
95
  name,
@@ -103,7 +113,7 @@ const fixtures = vitestTest
103
113
  isConcurrent: task.concurrent === true,
104
114
  failed: () => task.result?.state === "fail",
105
115
  testserverFailed: () => stormTestserverFailure.failed,
106
- featureFlagsKey: featureFlagsKey(featureFlags),
116
+ containerKey,
107
117
  startShared: (replacing) => startWarmed("file", task.file.name, replacing),
108
118
  startOwn: () => startWarmed("test", task.name),
109
119
  report: (text) => console.error(text),
@@ -115,7 +125,8 @@ const fixtures = vitestTest
115
125
  // again a test's fixture whose setup threw, and hands its dependents `undefined` in every later attempt
116
126
  // (vitest-dev/vitest#11237). So a retry after this one threw finds it `undefined`, and `container`, whose setup
117
127
  // Vitest has not run yet, sets the container up itself. That covers one retry: when `container` throws too, a
118
- // later attempt has no container (`startedContainer`). Later Vitest sets this one up again for every attempt.
128
+ // later attempt has no container (`startedContainer`). Vitest 5.0.4 and later, which storm's Vitest peer range
129
+ // allows, set this one up again for each attempt, so there every retry starts a container.
119
130
  // Remove the split once storm's Vitest peer range (`package.json`) requires 5.0.4 or later: `container` becomes the
120
131
  // one fixture again, and `stormContainerSetup`, `stormContainer` and `startedContainer` go.
121
132
  .extend("stormContainer", ({ stormContainerSetup }, { onCleanup }) => stormContainerSetup(onCleanup))
@@ -123,7 +134,7 @@ const fixtures = vitestTest
123
134
  const provided = stormContainer;
124
135
  return provided ?? stormContainerSetup(onCleanup);
125
136
  })
126
- .extend("proxy", async ({ container, stormFile, stormTestserverFailure, verbose, signal, onTestFailed, onTestFinished }, { onCleanup }) => {
137
+ .extend("proxy", async ({ container, recordHeaders, stormFile, stormTestserverFailure, verbose, signal, onTestFailed, onTestFinished }, { onCleanup }) => {
127
138
  startedContainer(container);
128
139
  // Under a verbose run, each request prints as the proxy records it, for passing tests too.
129
140
  const onRequest = verbose
@@ -138,7 +149,13 @@ const fixtures = vitestTest
138
149
  if (failure.message !== undefined)
139
150
  throw new Error(failure.message);
140
151
  });
141
- const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup, () => startProxy({ container, ...(onRequest === undefined ? {} : { onRequest }) }),
152
+ const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup,
153
+ // The proxy's records also show the Vercel CLI invoker's session id header, which its report counts by.
154
+ () => startProxy({
155
+ container,
156
+ recordHeaders: [VERCEL_CLI_SESSION_ID_HEADER, ...recordHeaders],
157
+ ...(onRequest === undefined ? {} : { onRequest }),
158
+ }),
142
159
  // Checked once closed, when every record has ended: a test whose fault rule forwarded a request Testserver
143
160
  // failed fails, since its premise, what Testserver answered, never held, and so does one whose proxied
144
161
  // request Testserver refused because it had stopped the container; in `'file'` scope either ends the
@@ -187,6 +204,14 @@ const fixtures = vitestTest
187
204
  * set before any service starts. A suite sets it on its own `test` with `.override("featureFlags", {...})`, a file
188
205
  * or `describe` with `test.override({ featureFlags })`; a value replaces the whole object. In `'file'` scope, a
189
206
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
207
+ * - `recordHeaders`: the headers whose values the container's and the proxy's records show as sent besides the
208
+ * SDK's defaults (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`, by default none. Every other header's value reads `<redacted>`, but `authorization`,
209
+ * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). The proxy's
210
+ * records also show `x-vercel-cli-session-id`, the Vercel CLI invoker's session id. A suite sets it on its own
211
+ * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
212
+ * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
213
+ * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
214
+ * any container is acquired.
190
215
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
191
216
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
192
217
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -196,7 +221,8 @@ const fixtures = vitestTest
196
221
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
197
222
  * container, its test id.
198
223
  * A retry of a test whose container failed to start starts one again, once: Vitest before 5.0.4 sets no fixture up
199
- * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container.
224
+ * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container. Vitest
225
+ * 5.0.4 and later start one again in each retry.
200
226
  * - `proxy`: a proxy adding `container`'s test id, per test, closed after it. Once closed, its cleanup fails the
201
227
  * test when a fault rule forwarded a request and Testserver failed (`fault.upstream.error`), or Testserver refused a
202
228
  * request because it had stopped the container; a rule with hits left doesn't.
@@ -25,6 +25,15 @@ export interface TestserverTestFixtureSet {
25
25
  * those of the file's container ends it and gets a new one.
26
26
  */
27
27
  featureFlags: FeatureFlags;
28
+ /**
29
+ * The headers whose values the container's and the proxy's records show as sent besides the SDK's defaults
30
+ * (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`; by default none, so every other header's
31
+ * value reads `<redacted>`. The proxy's records also show the `vercel` CLI's
32
+ * `x-vercel-cli-session-id`. Set it with `.override("recordHeaders", [...])` on a suite's `test`, or
33
+ * `test.override({ recordHeaders })`. In `'file'` scope, a test whose list shows other headers than that of the
34
+ * file's container ends it and gets a new one, as for `featureFlags`.
35
+ */
36
+ recordHeaders: readonly string[];
28
37
  /** The file's container in `'file'` scope, or the test's own in `'test'` scope. */
29
38
  container: Container;
30
39
  /** A proxy adding `container`'s test id, closed after the test. */
@@ -1,6 +1,7 @@
1
1
  // storm's Vitest driver: what the launcher knows of vitest, the program `storm vitest`'s command starts. It names the
2
- // binary, builds the `vitest run` argv, counts the tests with `vitest list` over its Context (`plan/`), and holds
3
- // the words that name vitest: `storm vitest`'s leaf help, what its run's summary says to do next, and what its two
2
+ // binary, builds the `vitest run` argv, counts for a run that counts (`testPlan` in `storm.config.ts`) the test files
3
+ // with `vitest list --filesOnly` over its Context (`plan/`), or each test with `vitest list` under `--count-tests`, and
4
+ // holds the words that name vitest: `storm vitest`'s leaf help, what its run's summary says to do next, and what its two
4
5
  // refusals say. The launcher makes `storm vitest` from it (`defineRunCommand`), reaching it through the registry
5
6
  // (`src/extensions.ts`).
6
7
  import { argsText, defineDriver } from "../../sdk/extension/index.js";
@@ -12,18 +13,21 @@ export const vitestDriver = defineDriver({
12
13
  program: { bin: "vitest" },
13
14
  context: () => ({ list: liveVitestListGateway }),
14
15
  launch: vitestRunArgv,
15
- // `vitest list --json <args>`, which may take 60s (`LIST_TIMEOUT_MS`); a failure in `describeVitestListFailure`'s
16
- // words.
17
- plan: ({ list }) => async ({ args, cwd, bin, signal }) => {
18
- const planned = await planVitestRunOver({ args, cwd, executable: bin, signal }, list);
16
+ // For a run that counts, `vitest list <args> --filesOnly --json`, or `vitest list <args> --json` under
17
+ // `--count-tests`, which may take 60s (`LIST_TIMEOUT_MS`); a failure in `describeVitestListFailure`'s words.
18
+ plan: ({ list }) => async ({ args, cwd, bin, countTests, signal }) => {
19
+ const planned = await planVitestRunOver({ args, cwd, executable: bin, countTests, signal }, list);
19
20
  if (planned.ok)
20
21
  return planned;
21
22
  const { failure } = planned;
22
23
  return { ok: false, kind: failure.kind, message: describeVitestListFailure(failure) };
23
24
  },
25
+ countTests: {
26
+ description: "Count each test before the run with vitest list --json, not only the test files with vitest list --filesOnly --json. vitest list then imports every test file on this machine to collect its tests, which can take most of a minute for a suite of hundreds of files and needs what the test files import to resolve here, such as a current build of the workspace's packages. In return, the run refuses with no_matching_tests when a -t matches no test, and its test plan holds the number of tests. It counts whether or not storm.config.ts sets testPlan. Without it, a run whose storm.config.ts sets testPlan counts only the files, which applies the file filters and --project but not -t: a -t that matches no test starts the run, and vitest run skips every test and exits 0.",
27
+ },
24
28
  help: {
25
- usage: "[<vitest run args>...] [-- <vitest dash options>...]",
26
- args: "What vitest run gets, unchanged and in order: every argument that isn't one of storm's flags, such as file filters, then everything after --, such as -t or --project. vitest list --json gets the same arguments when it counts the tests.",
29
+ usage: "[--count-tests] [<vitest run args>...] [-- <vitest dash options>...]",
30
+ args: "What vitest run gets, unchanged and in order: every argument that isn't one of storm's flags, such as file filters, then everything after --, such as -t or --project. vitest list gets the same arguments when it counts the test files, where storm.config.ts sets testPlan, or the tests with --count-tests.",
27
31
  // What a Vitest project's storm code does with the run payload's `verbose`: `stormReporters()` picks vitest's
28
32
  // `verbose` reporter (`@vercel/storm/vitest/config`), and an extension's Vitest fixtures print as each test
29
33
  // goes.
@@ -31,31 +35,41 @@ export const vitestDriver = defineDriver({
31
35
  examples: [
32
36
  {
33
37
  argv: "",
34
- description: "Run every test in a runner sandbox, with the runner recipe, team, project and resources from storm.config.ts, each resource that sizes itself sized from the test count.",
38
+ description: "Run every test in a runner sandbox, with the runner recipe, team, project and resources from storm.config.ts. Where it sets testPlan, storm counts the test files first, and each resource that sizes itself is sized from that count.",
35
39
  },
36
40
  {
37
41
  argv: "test/api -- -t creates",
38
42
  description: "Run the tests named creates in the files under test/api.",
39
43
  },
44
+ {
45
+ argv: "--count-tests test/api -- -t creates",
46
+ description: "Count the tests named creates in the files under test/api before the run, refusing with no_matching_tests when there is none, then run them.",
47
+ },
40
48
  ],
41
49
  },
42
50
  hints: {
43
51
  // No final result: the Vitest config lacks `stormReporter`, or a `--reporter` on vitest's command line replaced it.
44
52
  noFinalResults: "add stormReporter() to vitest.config's reporters (@vercel/storm/vitest/config)",
53
+ // `stormReporters()` keeps vitest's own output and reports nothing outside a storm run, so the steps add it
54
+ // unconditionally. The package may install storm under either of its npm names.
55
+ addReporter: [
56
+ 'In the Vitest config the run loads (vitest.config.ts, or the file --config names), import { stormReporters } from "@vercel/storm/vitest/config" and set test.reporters to stormReporters(), as in defineConfig({ test: { reporters: stormReporters() } }). If test.reporters already lists reporters, keep them and add stormReporter() from the same module to the list instead. In a package that installs storm as @cnc-tools/storm, import from "@cnc-tools/storm/vitest/config".',
57
+ "Remove any --reporter from the arguments given to vitest run, since it replaces the config's reporters, storm's among them. Then run the same storm vitest command again.",
58
+ ],
45
59
  },
46
60
  refusals: {
47
61
  noMatchingTests: {
48
- description: "vitest list found no test for the arguments given to vitest run, so nothing was minted, acquired or started.",
62
+ description: "The run counts, since storm.config.ts sets testPlan or the run took --count-tests, and vitest list found no test file for the arguments given to vitest run, or no test with --count-tests, so nothing was minted, acquired or started.",
49
63
  message: ({ args, cwd }) => `vitest list found no test for vitest run ${argsText(args)} in ${cwd}. The command didn't run.`,
50
64
  next: ({ args }) => `Change the arguments given to vitest run (${argsText(args)}), then retry. Put vitest's own dash options after --.`,
51
65
  },
52
66
  planFailed: {
53
- description: "storm couldn't count the tests before the run: vitest wasn't found or failed to start, didn't finish within 60s, exited other than 0, or printed something other than a list of tests. Nothing was minted, acquired or started.",
67
+ description: "storm couldn't plan the run: vitest wasn't found, or, for a run that counts, vitest list failed to start, didn't finish within 60s, exited other than 0, or printed something other than a list of files or tests. Nothing was minted, acquired or started.",
54
68
  next: {
55
- "start-failed": "Install vitest in the package, or run the command with storm exec, which counts nothing.",
56
- "timed-out": "Check why vitest list doesn't finish, such as a global setup that waits, then retry.",
69
+ "start-failed": "Install vitest in the package, or run the command with storm exec, which needs no vitest.",
70
+ "timed-out": "Check why vitest list doesn't finish, such as a global setup that waits, then retry. Without --count-tests it counts only the files, which imports no test file, and without testPlan in storm.config.ts it counts nothing.",
57
71
  exited: "Fix what vitest list reports, then retry. vitest list takes the arguments vitest run does, but refuses some run-only options.",
58
- "unreadable-output": "Check that the package's vitest prints its list with --json, then retry.",
72
+ "unreadable-output": "Check that the package's vitest prints its list with --json, and with --filesOnly --json, then retry.",
59
73
  },
60
74
  },
61
75
  },
@@ -5,7 +5,10 @@ export interface ListedTest {
5
5
  /** The absolute path of its file. */
6
6
  readonly file: string;
7
7
  }
8
- /** What to list: `vitest list` with `args`, such as a project and file filters, and `--json`. */
8
+ /**
9
+ * What to list: `vitest list` with `args`, such as a project and file filters, and `--json` (`listTests`), or
10
+ * `--filesOnly --json` (`listFiles`).
11
+ */
9
12
  export interface VitestListRequest {
10
13
  /** Passed to `vitest list`, as `vitest run` takes them. */
11
14
  readonly args: readonly string[];
@@ -19,9 +22,10 @@ export interface VitestListRequest {
19
22
  readonly signal?: AbortSignal;
20
23
  }
21
24
  /**
22
- * Why the tests couldn't be listed: `vitest` couldn't be started (not on `PATH` or not found, or no such `cwd`), it
23
- * didn't finish within `timeoutMs`, it exited other than 0 (with the last line of its stderr that isn't blank or a
24
- * stack frame, empty when there is none), its output wasn't a list of tests, or the request's `signal` stopped it.
25
+ * Why the tests or files couldn't be listed: `vitest` couldn't be started (not on `PATH` or not found, or no such
26
+ * `cwd`), it didn't finish within `timeoutMs`, it exited other than 0 (with the last line of its stderr that isn't
27
+ * blank or a stack frame, empty when there is none), its output wasn't a list of tests or of files, or the request's
28
+ * `signal` stopped it.
25
29
  */
26
30
  export type VitestListFailure = {
27
31
  readonly kind: "start-failed";
@@ -47,7 +51,26 @@ export type VitestListResult = {
47
51
  readonly ok: false;
48
52
  readonly failure: VitestListFailure;
49
53
  };
54
+ export type VitestFileListResult = {
55
+ readonly ok: true;
56
+ /**
57
+ * The absolute path of each test file a `vitest run` with the same arguments would run, once for each Vitest
58
+ * project that runs it.
59
+ */
60
+ readonly files: readonly string[];
61
+ } | {
62
+ readonly ok: false;
63
+ readonly failure: VitestListFailure;
64
+ };
50
65
  export interface VitestListGateway {
51
- /** Lists the tests a `vitest run` with the same arguments would run, without running them. */
66
+ /**
67
+ * Lists the tests a `vitest run` with the same arguments would run, without running them. Vitest imports every test
68
+ * file to collect its tests.
69
+ */
52
70
  listTests(request: VitestListRequest): Promise<VitestListResult>;
71
+ /**
72
+ * Lists the test files a `vitest run` with the same arguments would run, without importing them. Vitest applies the
73
+ * file filters and the projects, not a test name filter (`-t`).
74
+ */
75
+ listFiles(request: VitestListRequest): Promise<VitestFileListResult>;
53
76
  }
@@ -1,3 +1,3 @@
1
- // storm's Vitest driver's gateway: listing the tests a `vitest run` would run, before any resource is acquired. The
2
- // live gateway is `live/list-gateway.ts`; the fake is `test/fakes/extensions/vitest/plan/list-gateway.ts`.
1
+ // storm's Vitest driver's gateway: listing the tests a `vitest run` would run, or only their files, before any resource
2
+ // is acquired. The live gateway is `live/list-gateway.ts`; the fake is `test/fakes/extensions/vitest/plan/list-gateway.ts`.
3
3
  export {};
@@ -1,3 +1,8 @@
1
1
  import type { ListedTest } from "./gateways.ts";
2
2
  /** The tests `stdout` names. Throws an `Error` when it isn't JSON, or isn't a list of tests. */
3
3
  export declare function readVitestList(stdout: string): readonly ListedTest[];
4
+ /**
5
+ * The test files `stdout` names, once for each Vitest project that runs them. Throws an `Error` when it isn't JSON, or
6
+ * isn't a list of files.
7
+ */
8
+ export declare function readVitestFileList(stdout: string): readonly string[];
@@ -1,19 +1,33 @@
1
- // Reading `vitest list --json`'s output: a JSON array with one `{ name, file }` object per test. Pure, so the live
2
- // gateway and `parseVitestList` (`plan.ts`) share it.
1
+ // Reading `vitest list`'s output: with `--json`, a JSON array with one `{ name, file }` object per test; with
2
+ // `--filesOnly --json`, a JSON array with one `{ file }` object per test file and Vitest project. Pure, so the live
3
+ // gateway and `parseVitestList` and `parseVitestFileList` (`plan.ts`) share it.
3
4
  import { z } from "zod";
4
5
  /** `vitest list --json`'s output; other fields, such as `projectName`, pass through unchecked. */
5
6
  const VITEST_LIST = z.array(z.looseObject({ name: z.string(), file: z.string() }));
7
+ /** `vitest list --filesOnly --json`'s output; other fields, such as `projectName`, pass through unchecked. */
8
+ const VITEST_FILE_LIST = z.array(z.looseObject({ file: z.string() }));
6
9
  /** The tests `stdout` names. Throws an `Error` when it isn't JSON, or isn't a list of tests. */
7
10
  export function readVitestList(stdout) {
8
- let document;
11
+ const parsed = VITEST_LIST.safeParse(readJson(stdout, "`vitest list --json`"));
12
+ if (!parsed.success)
13
+ throw new Error("`vitest list --json` did not print a list of tests");
14
+ return parsed.data.map(({ name, file }) => ({ name, file }));
15
+ }
16
+ /**
17
+ * The test files `stdout` names, once for each Vitest project that runs them. Throws an `Error` when it isn't JSON, or
18
+ * isn't a list of files.
19
+ */
20
+ export function readVitestFileList(stdout) {
21
+ const parsed = VITEST_FILE_LIST.safeParse(readJson(stdout, "`vitest list --filesOnly --json`"));
22
+ if (!parsed.success)
23
+ throw new Error("`vitest list --filesOnly --json` did not print a list of files");
24
+ return parsed.data.map(({ file }) => file);
25
+ }
26
+ function readJson(stdout, command) {
9
27
  try {
10
- document = JSON.parse(stdout);
28
+ return JSON.parse(stdout);
11
29
  }
12
30
  catch {
13
- throw new Error("`vitest list --json` did not print JSON");
31
+ throw new Error(`${command} did not print JSON`);
14
32
  }
15
- const parsed = VITEST_LIST.safeParse(document);
16
- if (!parsed.success)
17
- throw new Error("`vitest list --json` did not print a list of tests");
18
- return parsed.data.map(({ name, file }) => ({ name, file }));
19
33
  }
@@ -1,7 +1,8 @@
1
1
  import type { VitestListGateway } from "../gateways.ts";
2
2
  /**
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`
3
+ * The live list gateway. `listTests` spawns `vitest list <args> --json`, and `listFiles` `vitest list <args>
4
+ * --filesOnly --json` (`listArgv`), the request's `executable` or `vitest` from `PATH`, no shell, in `cwd`, with stdin
5
+ * ignored. It sends SIGTERM after `timeoutMs`
5
6
  * (`AbortSignal.timeout`), or once the request's `signal` aborts, then waits for the process to exit and answers
6
7
  * `timed-out` or `canceled`, `canceled` when the request's `signal` aborted. It waits for the exit, not for the pipes
7
8
  * to close, since a process `vitest` left behind could hold them open. Any other `error` is a start failure, answered