@cnc-tools/storm 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) 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/arguments.d.ts +10 -4
  68. package/dist/extensions/testserver/vercel-cli/arguments.js +17 -6
  69. package/dist/extensions/testserver/vercel-cli/environment.d.ts +12 -1
  70. package/dist/extensions/testserver/vercel-cli/environment.js +35 -5
  71. package/dist/extensions/testserver/vercel-cli/index.d.ts +1 -0
  72. package/dist/extensions/testserver/vercel-cli/index.js +1 -0
  73. package/dist/extensions/testserver/vercel-cli/invoker.d.ts +28 -13
  74. package/dist/extensions/testserver/vercel-cli/invoker.js +81 -67
  75. package/dist/extensions/testserver/vercel-cli/live/process-gateway.js +4 -10
  76. package/dist/extensions/testserver/vercel-cli/report.js +5 -2
  77. package/dist/extensions/testserver/vercel-cli/session-id.d.ts +8 -0
  78. package/dist/extensions/testserver/vercel-cli/session-id.js +17 -0
  79. package/dist/extensions/testserver/vitest/config.d.ts +2 -2
  80. package/dist/extensions/testserver/vitest/config.js +2 -2
  81. package/dist/extensions/testserver/vitest/container-scope.d.ts +25 -16
  82. package/dist/extensions/testserver/vitest/container-scope.js +32 -13
  83. package/dist/extensions/testserver/vitest/diagnostics.d.ts +14 -12
  84. package/dist/extensions/testserver/vitest/diagnostics.js +29 -21
  85. package/dist/extensions/testserver/vitest/fixtures.d.ts +14 -1
  86. package/dist/extensions/testserver/vitest/fixtures.js +41 -12
  87. package/dist/extensions/testserver/vitest/types.d.ts +16 -0
  88. package/dist/extensions/vitest/driver.js +28 -14
  89. package/dist/extensions/vitest/plan/gateways.d.ts +28 -5
  90. package/dist/extensions/vitest/plan/gateways.js +2 -2
  91. package/dist/extensions/vitest/plan/list-output.d.ts +5 -0
  92. package/dist/extensions/vitest/plan/list-output.js +23 -9
  93. package/dist/extensions/vitest/plan/live/list-gateway.d.ts +3 -2
  94. package/dist/extensions/vitest/plan/live/list-gateway.js +77 -64
  95. package/dist/extensions/vitest/plan/plan-over.d.ts +19 -7
  96. package/dist/extensions/vitest/plan/plan-over.js +18 -7
  97. package/dist/extensions/vitest/plan/plan.d.ts +14 -5
  98. package/dist/extensions/vitest/plan/plan.js +23 -9
  99. package/dist/extensions.d.ts +2 -2
  100. package/dist/run-directory/plan.d.ts +3 -2
  101. package/dist/run-directory/plan.js +6 -3
  102. package/dist/run-directory/run-record.d.ts +4 -3
  103. package/dist/runner/recipe.d.ts +5 -1
  104. package/dist/runner/sandboxed-command.d.ts +5 -3
  105. package/dist/runner/sandboxed-command.js +10 -4
  106. package/dist/sdk/extension/driver.d.ts +32 -6
  107. package/dist/sdk/extension/driver.js +12 -2
  108. package/dist/sdk/extension/index.d.ts +1 -1
  109. package/dist/sdk/extension/index.js +2 -1
  110. package/dist/sdk/extension/resource-definition.d.ts +6 -5
  111. package/dist/vendor/testserver-sdk/container/api-request.d.ts +2 -3
  112. package/dist/vendor/testserver-sdk/container/api-request.js +2 -3
  113. package/dist/vendor/testserver-sdk/container/container.d.ts +12 -2
  114. package/dist/vendor/testserver-sdk/container/container.js +10 -7
  115. package/dist/vendor/testserver-sdk/container/recorder.d.ts +29 -7
  116. package/dist/vendor/testserver-sdk/container/recorder.js +26 -14
  117. package/dist/vendor/testserver-sdk/index.d.ts +1 -1
  118. package/dist/vendor/testserver-sdk/index.js +1 -1
  119. package/dist/vendor/testserver-sdk/proxy/exchange.d.ts +24 -5
  120. package/dist/vendor/testserver-sdk/proxy/exchange.js +43 -25
  121. package/dist/vendor/testserver-sdk/proxy/faulted-exchange.js +15 -10
  122. package/dist/vendor/testserver-sdk/proxy/faults.d.ts +6 -5
  123. package/dist/vendor/testserver-sdk/proxy/proxy.d.ts +10 -1
  124. package/dist/vendor/testserver-sdk/proxy/proxy.js +5 -3
  125. package/dist/vendor/testserver-sdk/proxy/records.d.ts +17 -17
  126. package/dist/vendor/testserver-sdk/proxy/records.js +18 -17
  127. package/dist/vendor/testserver-sdk/records/body.d.ts +7 -9
  128. package/dist/vendor/testserver-sdk/records/body.js +10 -15
  129. package/dist/vendor/testserver-sdk/records/headers.d.ts +79 -0
  130. package/dist/vendor/testserver-sdk/records/headers.js +162 -0
  131. package/dist/vendor/testserver-sdk/records/index.d.ts +2 -1
  132. package/dist/vendor/testserver-sdk/records/index.js +4 -2
  133. package/dist/vendor/testserver-sdk/records/records.d.ts +19 -10
  134. package/package.json +5 -4
  135. package/skills/overview.md +5 -5
  136. package/skills/testserver-builds.md +0 -82
@@ -1,18 +1,19 @@
1
- import { describeFailure, FEATURE_FLAG_CLIENTS, REDACTED, redactTokenFields, TestserverCallError, } from "../../../vendor/testserver-sdk/index.js";
1
+ import { describeFailure, FEATURE_FLAG_CLIENTS, REDACTED, REDACTED_HEADER, redactTokenFields, TestserverCallError, } from "../../../vendor/testserver-sdk/index.js";
2
2
  /** The most characters of one body, input, response or container log line a failure report prints. */
3
3
  export const BODY_REPORT_CHARS = 1000;
4
4
  /** The most container log records a failure report prints, the last ones. */
5
5
  export const LOG_REPORT_RECORDS = 50;
6
6
  /**
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
9
- * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
10
- * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
11
- * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
12
- * 200)`. A status that fails the call (a record's `failure`) reads with why, such as `503 (the container stopped: …)`,
13
- * and an answer that broke off after its status with `then failed`, such as `200, then failed (aborted)`.
7
+ * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
8
+ * duration, and any session id from `sessionHeader` (both read from its `requestHeaders`, ignoring `<redacted>`),
9
+ * such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts with its external
10
+ * service, such as `external github POST /scenarios → 204, …`. A proxy record whose exchange was still open reads
11
+ * `open`, its duration counted to the read. A proxy record of a request a fault rule matched tags its result with the
12
+ * action and what Testserver answered, such as `500 (fault: replace, Testserver 200)`. A status that fails the call
13
+ * (a record's `failure`) reads with why, such as `503 (the container stopped: …)`, and an answer that broke off after
14
+ * its status with `then failed`, such as `200, then failed (aborted)`.
14
15
  */
15
- export function describeRequest(request) {
16
+ export function describeRequest(request, sessionHeader) {
16
17
  const result = "open" in request
17
18
  ? "open"
18
19
  : !("status" in request)
@@ -22,8 +23,10 @@ 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 rawSessionId = sessionHeader === undefined ? undefined : request.requestHeaders[sessionHeader.toLowerCase()];
28
+ const sessionId = rawSessionId === REDACTED_HEADER ? undefined : rawSessionId;
29
+ const session = sessionId === undefined ? "" : `, session ${sessionId}`;
27
30
  const fault = "fault" in request && request.fault !== undefined ? ` ${faultTag(request.fault)}` : "";
28
31
  const external = "externalId" in request ? `external ${request.externalId} ` : "";
29
32
  return `${external}${request.method} ${request.url} → ${result}${fault}, ${authorization}, ${Math.round(request.durationMs)}ms${session}`;
@@ -78,10 +81,10 @@ function cut(text, max) {
78
81
  * One request record as its line, then a line for each body it has: what the client sent and got, and what
79
82
  * Testserver answered under a forwarding fault.
80
83
  */
81
- function describeExchange(request, redact) {
84
+ function describeExchange(request, redact, sessionHeader) {
82
85
  const upstreamBody = "fault" in request ? request.fault?.upstream?.responseBody : undefined;
83
86
  return [
84
- redact(describeRequest(request)),
87
+ redact(describeRequest(request, sessionHeader)),
85
88
  ...(request.requestBody === undefined ? [] : [` request body: ${describeBody(request.requestBody, redact)}`]),
86
89
  ...(request.responseBody === undefined ? [] : [` response body: ${describeBody(request.responseBody, redact)}`]),
87
90
  ...(upstreamBody === undefined ? [] : [` Testserver response body: ${describeBody(upstreamBody, redact)}`]),
@@ -303,8 +306,8 @@ function listed(items) {
303
306
  * What a verbose run prints as the proxy records a request: the request line with its bodies, as a failure report
304
307
  * would show it, naming the test id.
305
308
  */
306
- export function proxyRequestReport(testId, request, redact) {
307
- return [`storm: the proxy for test id ${testId} received:`, ...describeExchange(request, redact)].join("\n ");
309
+ export function proxyRequestReport(testId, request, redact, sessionHeader) {
310
+ return [`storm: the proxy for test id ${testId} received:`, ...describeExchange(request, redact, sessionHeader)].join("\n ");
308
311
  }
309
312
  /**
310
313
  * One warmup as a failure report's line: how many services, how long, and each that failed with why, such as
@@ -317,20 +320,25 @@ export function describeWarmup(warmup, redact) {
317
320
  }
318
321
  /**
319
322
  * 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
323
+ * 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
324
  * has, any warmup after it with the services that failed, and its test id, such as `storm: started a container for
322
325
  * the file a.test.ts in 812ms, 1 feature flag, warmed 3 services in 2140ms (1 failed: api-projects), test id ts-…`.
323
326
  */
324
327
  export function containerStartReport(start) {
325
328
  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"}),`;
329
+ const replacing = start.replaced === undefined ? "" : `, replacing the file's container (${REPLACED_BECAUSE[start.replaced]}),`;
329
330
  const count = countFeatureFlags(start.featureFlags ?? {});
330
331
  const flags = count === 0 ? "" : `, ${count} feature ${count === 1 ? "flag" : "flags"}`;
331
332
  const warmed = start.warmup === undefined ? "" : `, ${describeWarmed(start.warmup.warmup, start.warmup.ms)}`;
332
333
  return `storm: started a container for ${what}${replacing} in ${Math.round(start.ms)}ms${flags}${warmed}, test id ${start.testId}`;
333
334
  }
335
+ /** Why a container start replaced the file's container, as `containerStartReport` says it. */
336
+ const REPLACED_BECAUSE = {
337
+ "feature-flags": "feature flags differ",
338
+ "record-headers": "recordHeaders differ",
339
+ options: "feature flags and recordHeaders differ",
340
+ stopped: "Testserver had stopped it",
341
+ };
334
342
  /** `warmed 3 services in 2140ms`, with `(1 failed: api-projects)` when any failed. */
335
343
  function describeWarmed(warmup, ms) {
336
344
  const failed = warmup.services.flatMap((service) => (service.ok ? [] : [service.serviceId]));
@@ -346,12 +354,12 @@ function services(count) {
346
354
  * container's, so a secret the proxy's own redaction can't know of, such as another seeded token, reads `<token>`
347
355
  * too).
348
356
  */
349
- export function proxyFailureReport(testId, requests, redact, faults = []) {
357
+ export function proxyFailureReport(testId, requests, redact, faults = [], sessionHeader) {
350
358
  const received = requests.length === 0
351
359
  ? [`storm: the proxy for test id ${testId} received no requests`]
352
360
  : [
353
361
  `storm: requests the proxy received for test id ${testId}:`,
354
- ...requests.flatMap((request) => describeExchange(request, redact)).map((line) => ` ${line}`),
362
+ ...requests.flatMap((request) => describeExchange(request, redact, sessionHeader)).map((line) => ` ${line}`),
355
363
  ];
356
364
  const unused = faults.filter((handle) => handle.remaining > 0);
357
365
  const rules = unused.length === 0
@@ -42,6 +42,18 @@ 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`). A suite sets it on its own
48
+ * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
49
+ * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
50
+ * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
51
+ * any container is acquired.
52
+ * - `proxySessionHeader`: an optional request header name that `proxy` records in addition to `recordHeaders` and
53
+ * prints as `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`), by default
54
+ * `undefined`. A suite sets it on its own `test` with `.override("proxySessionHeader", ...)`, a file or `describe`
55
+ * with `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives
56
+ * per-test `recordHeaders` overrides, and never replaces a file-scoped container.
45
57
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
46
58
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
47
59
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -51,7 +63,8 @@ declare module "vitest" {
51
63
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
52
64
  * container, its test id.
53
65
  * 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.
66
+ * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container. Vitest
67
+ * 5.0.4 and later start one again in each retry.
55
68
  * - `proxy`: a proxy adding `container`'s test id, per test, closed after it. Once closed, its cleanup fails the
56
69
  * test when a fault rule forwarded a request and Testserver failed (`fault.upstream.error`), or Testserver refused a
57
70
  * request because it had stopped the container; a rule with hits left doesn't.
@@ -1,6 +1,6 @@
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";
@@ -10,6 +10,8 @@ import { reportedStart } from "./container-start.js";
10
10
  const NO_SERVICES = [];
11
11
  /** The default `featureFlags`: none. */
12
12
  const NO_FEATURE_FLAGS = {};
13
+ /** The default `recordHeaders`: none beyond the SDK's defaults, so records show every other header's value as `<redacted>`. */
14
+ const NO_RECORD_HEADERS = [];
13
15
  /**
14
16
  * `container`, the `container` fixture's value as another fixture reads it, or an error when there is none. Vitest
15
17
  * before 5.0.4 never sets up again a test's fixture whose setup threw, and hands its dependents `undefined` in every
@@ -71,15 +73,23 @@ const fixtures = vitestTest
71
73
  .extend("containerScope", CONTAINER_SCOPE)
72
74
  .extend("warmServices", NO_SERVICES)
73
75
  .extend("featureFlags", NO_FEATURE_FLAGS)
76
+ .extend("recordHeaders", NO_RECORD_HEADERS)
77
+ .extend("proxySessionHeader", undefined)
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,11 +134,11 @@ 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, proxySessionHeader, 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
130
- ? (record) => console.error(proxyRequestReport(container.testId, record, (text) => container.redact(text)))
141
+ ? (record) => console.error(proxyRequestReport(container.testId, record, (text) => container.redact(text), proxySessionHeader))
131
142
  : undefined;
132
143
  // Why Testserver failed the test through the proxy, once it has closed. The cleanup only notes it, and this
133
144
  // handler, which Vitest runs after every cleanup and before the failure handlers, fails the test with it: a
@@ -138,7 +149,12 @@ 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 proxyRecordHeaders = proxySessionHeader === undefined ? recordHeaders : [proxySessionHeader, ...recordHeaders];
153
+ const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup, () => startProxy({
154
+ container,
155
+ recordHeaders: proxyRecordHeaders,
156
+ ...(onRequest === undefined ? {} : { onRequest }),
157
+ }),
142
158
  // Checked once closed, when every record has ended: a test whose fault rule forwarded a request Testserver
143
159
  // failed fails, since its premise, what Testserver answered, never held, and so does one whose proxied
144
160
  // request Testserver refused because it had stopped the container; in `'file'` scope either ends the
@@ -152,7 +168,7 @@ const fixtures = vitestTest
152
168
  failure.message = message;
153
169
  }));
154
170
  onTestFailed(() => {
155
- console.error(proxyFailureReport(container.testId, proxy.requests, (text) => proxy.redact(text), proxy.faults));
171
+ console.error(proxyFailureReport(container.testId, proxy.requests, (text) => proxy.redact(text), proxy.faults, proxySessionHeader));
156
172
  });
157
173
  return proxy;
158
174
  });
@@ -187,6 +203,18 @@ const fixtures = vitestTest
187
203
  * set before any service starts. A suite sets it on its own `test` with `.override("featureFlags", {...})`, a file
188
204
  * or `describe` with `test.override({ featureFlags })`; a value replaces the whole object. In `'file'` scope, a
189
205
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
206
+ * - `recordHeaders`: the headers whose values the container's and the proxy's records show as sent besides the
207
+ * 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`,
208
+ * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). A suite sets it on its own
209
+ * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
210
+ * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
211
+ * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
212
+ * any container is acquired.
213
+ * - `proxySessionHeader`: an optional request header name that `proxy` records in addition to `recordHeaders` and
214
+ * prints as `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`), by default
215
+ * `undefined`. A suite sets it on its own `test` with `.override("proxySessionHeader", ...)`, a file or `describe`
216
+ * with `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives
217
+ * per-test `recordHeaders` overrides, and never replaces a file-scoped container.
190
218
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
191
219
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
192
220
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -196,7 +224,8 @@ const fixtures = vitestTest
196
224
  * name, and ended after it. The test's `task.meta.storm` records the Testserver URL and, once the test has the
197
225
  * container, its test id.
198
226
  * 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.
227
+ * again after its setup throws, so in a later attempt `proxy` fails, saying the attempt has no container. Vitest
228
+ * 5.0.4 and later start one again in each retry.
200
229
  * - `proxy`: a proxy adding `container`'s test id, per test, closed after it. Once closed, its cleanup fails the
201
230
  * test when a fault rule forwarded a request and Testserver failed (`fault.upstream.error`), or Testserver refused a
202
231
  * request because it had stopped the container; a rule with hits left doesn't.
@@ -25,6 +25,22 @@ 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>`. Set it with `.override("recordHeaders", [...])` on a suite's `test`, or
32
+ * `test.override({ recordHeaders })`. In `'file'` scope, a test whose list shows other headers than that of the
33
+ * file's container ends it and gets a new one, as for `featureFlags`.
34
+ */
35
+ recordHeaders: readonly string[];
36
+ /**
37
+ * An optional request header name that `proxy` records in addition to `recordHeaders` and prints as
38
+ * `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`); by default `undefined`.
39
+ * Set it with `.override("proxySessionHeader", ...)` on a suite's `test`, or
40
+ * `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives per-test
41
+ * `recordHeaders` overrides, and never replaces a file-scoped container.
42
+ */
43
+ proxySessionHeader: string | undefined;
28
44
  /** The file's container in `'file'` scope, or the test's own in `'test'` scope. */
29
45
  container: Container;
30
46
  /** 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