@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
@@ -3,10 +3,10 @@
3
3
  // invocations share. `createVercelCli` takes its Context; `vercelCli` (`entry.ts`), the published entry, passes the
4
4
  // live one.
5
5
  import { join } from "node:path";
6
- import { displayCommand, passesFlag, passesScopeFlag, vercelArguments } from "./arguments.js";
6
+ import { displayCommand, insertBeforeDoubleDash, passesFlag, passesScopeFlag, vercelArguments } from "./arguments.js";
7
7
  import { authFileConflict, authFileSettled, settledAuthConfig, VERCEL_AUTH_MODES, } from "./auth-config.js";
8
8
  import { AUTH_CONFIG_FILE, readConfigText, serializeConfig } from "./config-files.js";
9
- import { invocationEnvironment } from "./environment.js";
9
+ import { checkExtraEnvironment, invocationEnvironment, resolveExtraEnvironment } from "./environment.js";
10
10
  import { VercelCliError } from "./errors.js";
11
11
  import { Invocation, STOP_SIGNALS, WAIT_FOR_TIMEOUT_MS, } from "./invocation.js";
12
12
  import { KEY_SEQUENCES } from "./keys.js";
@@ -19,6 +19,9 @@ const DEFAULT_COMMAND = { file: "vercel", args: [] };
19
19
  /** A `VercelCli` over `context`. It prepares `<home>/global-config` and `<home>/work` first. */
20
20
  export async function createVercelCli(options, context) {
21
21
  const defaultTimeoutMs = checkedTimeout(options.timeoutMs ?? VERCEL_TIMEOUT_MS, "timeoutMs");
22
+ if (options.env !== undefined)
23
+ checkExtraEnvironment(options.env);
24
+ const initialEnv = options.env === undefined ? {} : { ...options.env };
22
25
  const home = options.home;
23
26
  const globalConfigDir = join(home, "global-config");
24
27
  const workDir = join(home, "work");
@@ -52,7 +55,7 @@ export async function createVercelCli(options, context) {
52
55
  * and `close()` kills it even while it is starting. Then it settles `auth.json` for a saved login or a logged-out
53
56
  * invocation, after any settlement already under way, and starts the process.
54
57
  */
55
- const launch = async (args, call, how) => {
58
+ const launch = async (args, call, handleEnv, how) => {
56
59
  const { interactive, stdin } = how;
57
60
  const terminal = stdin.kind === "terminal";
58
61
  const authentication = resolveAuthentication(checkedAuth(call.auth ?? defaultAuth), call.as, identity?.token);
@@ -67,7 +70,13 @@ export async function createVercelCli(options, context) {
67
70
  globalConfigDir,
68
71
  scope,
69
72
  });
70
- const env = invocationEnvironment({ host: hostEnv, home, terminal, columns: how.columns, extra: call.env });
73
+ const env = invocationEnvironment({
74
+ host: hostEnv,
75
+ home,
76
+ terminal,
77
+ columns: how.columns,
78
+ extra: resolveExtraEnvironment(handleEnv, call.env),
79
+ });
71
80
  const cwd = call.cwd ?? workDir;
72
81
  const conflict = invocations.find((other) => other.running && authFileConflict(authentication, other.authentication));
73
82
  if (conflict !== undefined)
@@ -168,11 +177,11 @@ export async function createVercelCli(options, context) {
168
177
  * result once it has ended. Kills it when `block` throws. Every call but `json` runs through here; `run`'s block
169
178
  * does nothing.
170
179
  */
171
- const execute = async (args, call, interactive, block) => {
180
+ const execute = async (args, call, handleEnv, interactive, block) => {
172
181
  const stdin = invocationStdin(call);
173
182
  const columns = invocationColumns(call);
174
183
  const terminal = stdin.kind === "terminal";
175
- const invocation = await launch(args, call, { interactive, stdin, columns });
184
+ const invocation = await launch(args, call, handleEnv, { interactive, stdin, columns });
176
185
  try {
177
186
  await block(handle(invocation, terminal));
178
187
  }
@@ -185,69 +194,74 @@ export async function createVercelCli(options, context) {
185
194
  invocation.closeStdin();
186
195
  return invocation.result();
187
196
  };
188
- async function interact(args, callOrBlock, maybeBlock) {
189
- const [call, block] = typeof callOrBlock === "function" ? [{}, callOrBlock] : [callOrBlock, maybeBlock];
190
- if (typeof block !== "function") {
191
- throw new TypeError("vercel-cli: interact takes a block: interact(args, options?, async (invocation) => ...)");
192
- }
193
- return execute(args, call, true, block);
194
- }
195
- return {
196
- home,
197
- globalConfigDir,
198
- workDir,
199
- actAs({ token, team }, actAsOptions = {}) {
200
- if (token.secretString === "")
201
- throw new TypeError("vercel-cli: actAs names an empty token");
202
- if (team !== null && team.slug === "")
203
- throw new TypeError("vercel-cli: actAs names a team with an empty slug");
204
- const auth = checkedAuth(actAsOptions.auth ?? "flag");
205
- redactor.add(token.secretString);
206
- identity = { token: token.secretString, scope: team?.slug };
207
- defaultAuth = auth;
208
- },
209
- run: async (args, call = {}) => execute(args, call, false, () => undefined),
210
- interact,
211
- async json(args, schema, call = {}) {
212
- if (passesFlag(args, "--format")) {
213
- throw new TypeError("vercel-cli: json adds --format json itself; leave --format out of the arguments");
214
- }
215
- const invocation = await launch([...args, "--format", "json"], call, {
216
- interactive: false,
217
- stdin: { kind: "ignored" },
218
- });
219
- const result = await invocation.result();
220
- const failed = (why) => new VercelCliError(`vercel-cli: invocation ${invocation.number} ${why}\n${describeInvocation(invocation.snapshot())}`);
221
- if (result.exitCode !== 0 || result.timedOut || result.aborted)
222
- throw failed("didn't exit 0");
223
- let document;
224
- try {
225
- document = JSON.parse(result.stdout);
226
- }
227
- catch {
228
- throw failed("printed something other than JSON");
229
- }
230
- const parsed = schema.safeParse(document);
231
- if (!parsed.success) {
232
- const issue = parsed.error.issues[0];
233
- const where = issue === undefined || issue.path.length === 0 ? "" : ` at ${issue.path.map(String).join(".")}`;
234
- throw failed(`printed JSON its schema rejects${where}: ${redactor.redact(issue?.message ?? "invalid")}`);
197
+ const actAs = ({ token, team }, actAsOptions = {}) => {
198
+ if (token.secretString === "")
199
+ throw new TypeError("vercel-cli: actAs names an empty token");
200
+ if (team !== null && team.slug === "")
201
+ throw new TypeError("vercel-cli: actAs names a team with an empty slug");
202
+ const auth = checkedAuth(actAsOptions.auth ?? "flag");
203
+ redactor.add(token.secretString);
204
+ identity = { token: token.secretString, scope: team?.slug };
205
+ defaultAuth = auth;
206
+ };
207
+ const close = async () => {
208
+ const running = invocations.filter((invocation) => invocation.running);
209
+ for (const invocation of running)
210
+ invocation.kill("close");
211
+ await Promise.all(running.map((invocation) => invocation.ended()));
212
+ };
213
+ const failureReport = () => describeInvocations(invocations.map((invocation) => invocation.snapshot()));
214
+ const cliWithEnv = (handleEnv) => {
215
+ async function interact(args, callOrBlock, maybeBlock) {
216
+ const [call, block] = typeof callOrBlock === "function" ? [{}, callOrBlock] : [callOrBlock, maybeBlock];
217
+ if (typeof block !== "function") {
218
+ throw new TypeError("vercel-cli: interact takes a block: interact(args, options?, async (invocation) => ...)");
235
219
  }
236
- return parsed.data;
237
- },
238
- get invocations() {
239
- return invocations.map((invocation) => invocation.snapshot());
240
- },
241
- async close() {
242
- const running = invocations.filter((invocation) => invocation.running);
243
- for (const invocation of running)
244
- invocation.kill("close");
245
- await Promise.all(running.map((invocation) => invocation.ended()));
246
- },
247
- failureReport() {
248
- return describeInvocations(invocations.map((invocation) => invocation.snapshot()));
249
- },
220
+ return execute(args, call, handleEnv, true, block);
221
+ }
222
+ return {
223
+ home,
224
+ globalConfigDir,
225
+ workDir,
226
+ actAs,
227
+ withEnv: (extra) => cliWithEnv(resolveExtraEnvironment(handleEnv, extra)),
228
+ run: async (args, call = {}) => execute(args, call, handleEnv, false, () => undefined),
229
+ interact,
230
+ async json(args, schema, call = {}) {
231
+ if (passesFlag(args, "--format")) {
232
+ throw new TypeError("vercel-cli: json adds --format json itself; leave --format out of the arguments");
233
+ }
234
+ const invocation = await launch(insertBeforeDoubleDash(args, ["--format", "json"]), call, handleEnv, {
235
+ interactive: false,
236
+ stdin: { kind: "ignored" },
237
+ });
238
+ const result = await invocation.result();
239
+ const failed = (why) => new VercelCliError(`vercel-cli: invocation ${invocation.number} ${why}\n${describeInvocation(invocation.snapshot())}`);
240
+ if (result.exitCode !== 0 || result.timedOut || result.aborted)
241
+ throw failed("didn't exit 0");
242
+ let document;
243
+ try {
244
+ document = JSON.parse(result.stdout);
245
+ }
246
+ catch {
247
+ throw failed("printed something other than JSON");
248
+ }
249
+ const parsed = schema.safeParse(document);
250
+ if (!parsed.success) {
251
+ const issue = parsed.error.issues[0];
252
+ const where = issue === undefined || issue.path.length === 0 ? "" : ` at ${issue.path.map(String).join(".")}`;
253
+ throw failed(`printed JSON its schema rejects${where}: ${redactor.redact(issue?.message ?? "invalid")}`);
254
+ }
255
+ return parsed.data;
256
+ },
257
+ get invocations() {
258
+ return invocations.map((invocation) => invocation.snapshot());
259
+ },
260
+ close,
261
+ failureReport,
262
+ };
250
263
  };
264
+ return cliWithEnv(initialEnv);
251
265
  }
252
266
  /** A `TypeError` for starting `wanted` while `other`, still running, needs `auth.json` to hold something else. */
253
267
  function authFileConflictError(wanted, other) {
@@ -61,7 +61,6 @@ function startProcess(request) {
61
61
  let started = false;
62
62
  let completed = false;
63
63
  let terminated = false;
64
- let drainExpired = false;
65
64
  let drainTimer;
66
65
  let processExit;
67
66
  let stdinOpen = request.stdin === "pipe";
@@ -78,19 +77,14 @@ function startProcess(request) {
78
77
  clearTimeout(drainTimer);
79
78
  resolveExit(exit);
80
79
  };
81
- const stopDraining = () => {
82
- if (!drainExpired || processExit === undefined)
83
- return;
84
- complete({ ...processExit, outputComplete: false });
85
- child.stdout?.destroy();
86
- child.stderr?.destroy();
87
- };
88
80
  const startDrainTimer = () => {
89
81
  if (!terminated || processExit === undefined || drainTimer !== undefined || completed)
90
82
  return;
83
+ const exit = processExit;
91
84
  drainTimer = setTimeout(() => {
92
- drainExpired = true;
93
- stopDraining();
85
+ complete({ ...exit, outputComplete: false });
86
+ child.stdout?.destroy();
87
+ child.stderr?.destroy();
94
88
  }, TERMINATE_DRAIN_MS);
95
89
  };
96
90
  // A write racing the process's exit fails with EPIPE; the invoker learns of the exit from `exited`.
@@ -2,6 +2,7 @@
2
2
  // them and unit tests can check them.
3
3
  import { isOpenRecord } from "../../../vendor/testserver-sdk/index.js";
4
4
  import { STOP_GRACE_MS } from "./invocation.js";
5
+ import { vercelCliSessionId } from "./session-id.js";
5
6
  /** The most characters of each of an invocation's stdout and stderr a report prints: the last ones. */
6
7
  export const OUTPUT_REPORT_CHARS = 4000;
7
8
  /** The most characters of an invocation's piped stdin text a report prints: the first ones. */
@@ -70,8 +71,10 @@ export function describeRequests(requests) {
70
71
  if (requests.length === 0)
71
72
  return "no proxy requests while it ran";
72
73
  const counts = new Map();
73
- for (const request of requests)
74
- counts.set(request.sessionId, (counts.get(request.sessionId) ?? 0) + 1);
74
+ for (const request of requests) {
75
+ const session = vercelCliSessionId(request.requestHeaders);
76
+ counts.set(session, (counts.get(session) ?? 0) + 1);
77
+ }
75
78
  const sessions = [...counts].map(([session, count]) => session === undefined ? `no session id (${count})` : `session ${session} (${count})`);
76
79
  const noun = requests.length === 1 ? "proxy request" : "proxy requests";
77
80
  const open = requests.filter(isOpenRecord).length;
@@ -0,0 +1,8 @@
1
+ import { type RecordedHeaders } from "../../../vendor/testserver-sdk/index.js";
2
+ /** The header the `vercel` CLI sends with the same id on every request of one invocation. */
3
+ export declare const VERCEL_CLI_SESSION_ID_HEADER = "x-vercel-cli-session-id";
4
+ /**
5
+ * The `vercel` CLI's session id a request record's `requestHeaders` hold, or `undefined` when it sent none or the
6
+ * record hides it, because its proxy's `recordHeaders` doesn't name the header.
7
+ */
8
+ export declare function vercelCliSessionId(requestHeaders: RecordedHeaders): string | undefined;
@@ -0,0 +1,17 @@
1
+ // The `vercel` CLI's session id, read from a request record's headers. The Vercel CLI invoker's failure report counts
2
+ // proxy records by it, and a suite using the Testserver Vitest fixtures can pass `VERCEL_CLI_SESSION_ID_HEADER` to
3
+ // `proxySessionHeader` so the proxy records it and prints `, session <id>` on request lines. A record shows a header's
4
+ // value only when its proxy's `recordHeaders` names it; a proxy that doesn't leaves every record without a session id.
5
+ // It belongs with the `vercel` CLI's own tests, and moves to vercel-internal with the invoker. It loads no other file
6
+ // at run time.
7
+ import { REDACTED_HEADER } from "../../../vendor/testserver-sdk/index.js";
8
+ /** The header the `vercel` CLI sends with the same id on every request of one invocation. */
9
+ export const VERCEL_CLI_SESSION_ID_HEADER = "x-vercel-cli-session-id";
10
+ /**
11
+ * The `vercel` CLI's session id a request record's `requestHeaders` hold, or `undefined` when it sent none or the
12
+ * record hides it, because its proxy's `recordHeaders` doesn't name the header.
13
+ */
14
+ export function vercelCliSessionId(requestHeaders) {
15
+ const sessionId = requestHeaders[VERCEL_CLI_SESSION_ID_HEADER];
16
+ return sessionId === REDACTED_HEADER ? undefined : sessionId;
17
+ }
@@ -8,8 +8,8 @@ export { WORKERS_PER_SANDBOX } from "../run/sandbox.ts";
8
8
  * container after a test whose factory call, API request or proxied request failed so, so the retry runs on a new
9
9
  * container, where a factory call that half-happened on the old one can't collide with it. vitest's own output marks
10
10
  * a test it rescued `(retry x1)`. Spread it to change the count: `retry: { ...testserverTransientRetry, count: 2 }`;
11
- * under Vitest before 5.0.4, only the first retry can start a container again after a failed start (the library's
12
- * `README.md`, `stormContainer`).
11
+ * under Vitest 4, and Vitest 5 before 5.0.4, only the first retry can start a container again after a failed start
12
+ * (the library's `README.md`, `stormContainer`), and under Vitest 5.0.4 and later each retry can.
13
13
  */
14
14
  export declare const testserverTransientRetry: {
15
15
  readonly count: number;
@@ -14,8 +14,8 @@ export { WORKERS_PER_SANDBOX } from "../run/sandbox.js";
14
14
  * container after a test whose factory call, API request or proxied request failed so, so the retry runs on a new
15
15
  * container, where a factory call that half-happened on the old one can't collide with it. vitest's own output marks
16
16
  * a test it rescued `(retry x1)`. Spread it to change the count: `retry: { ...testserverTransientRetry, count: 2 }`;
17
- * under Vitest before 5.0.4, only the first retry can start a container again after a failed start (the library's
18
- * `README.md`, `stormContainer`).
17
+ * under Vitest 4, and Vitest 5 before 5.0.4, only the first retry can start a container again after a failed start
18
+ * (the library's `README.md`, `stormContainer`), and under Vitest 5.0.4 and later each retry can.
19
19
  */
20
20
  export const testserverTransientRetry = {
21
21
  count: 1,
@@ -2,7 +2,7 @@ import { type Container, type ServiceWarmup, type TestserverServiceId } from "..
2
2
  /**
3
3
  * How long the Testserver Vitest fixtures' container lives: `'file'`, one container shared by a test file's tests and
4
4
  * replaced after a test that failed because of a Testserver failure (`endsSharedContainer`), for a test with different
5
- * feature flags, or for a test it reached after Testserver had stopped it, as Testserver's idle eviction does, or
5
+ * feature flags or a different `recordHeaders` list, or for a test it reached after Testserver had stopped it, as Testserver's idle eviction does, or
6
6
  * `'test'`, one per test.
7
7
  */
8
8
  export type ContainerScope = "file" | "test";
@@ -13,14 +13,23 @@ export type SharedContainer = Pick<Container, "testId" | "testserverUrl" | "feat
13
13
  /**
14
14
  * Where the container `FileContainer.acquire` hands out came from: `reused`, the file's running container; `new`,
15
15
  * one it started, or a start in flight it shared; `replaced`, one it started after ending the file's container,
16
- * which had different feature flags or which Testserver had stopped (`FileContainer.replaceStopped`).
16
+ * which had a different `ContainerKey` or which Testserver had stopped (`FileContainer.replaceStopped`).
17
17
  */
18
18
  export type ContainerOrigin = "new" | "reused" | "replaced";
19
+ /**
20
+ * What a file container is started for, which a test must match to share it: the canonical keys of the feature flags
21
+ * (`featureFlagsKey`) and of the `recordHeaders` list (`recordHeadersKey`) of the test that started it.
22
+ */
23
+ export interface ContainerKey {
24
+ readonly featureFlags: string;
25
+ readonly recordHeaders: string;
26
+ }
19
27
  /**
20
28
  * Why a new file container replaces the file's container: `feature-flags`, the file's had different feature flags;
21
- * `stopped`, Testserver had stopped the file's, as its idle eviction does.
29
+ * `record-headers`, it had a different `recordHeaders` list; `options`, it had both; `stopped`, Testserver had
30
+ * stopped the file's, as its idle eviction does.
22
31
  */
23
- export type ReplacedFor = "feature-flags" | "stopped";
32
+ export type ReplacedFor = "feature-flags" | "record-headers" | "options" | "stopped";
24
33
  /** The container `FileContainer.acquire` hands out, and where it came from. */
25
34
  export interface AcquiredContainer<C> {
26
35
  readonly container: C;
@@ -30,28 +39,28 @@ export interface AcquiredContainer<C> {
30
39
  export type StartFileContainer<C> = (replacing?: ReplacedFor) => Promise<C>;
31
40
  /**
32
41
  * A test file's container in `'file'` scope. It starts lazily, when the first test asks for it; concurrent
33
- * `acquire` calls with the same feature flags key share one start, and a failed start leaves nothing behind, so the
34
- * next `acquire` starts again. The container remembers the feature flags key it started with: a test with a
35
- * different one gets a new container, which replaces it.
42
+ * `acquire` calls with the same `ContainerKey` share one start, and a failed start leaves nothing behind, so the
43
+ * next `acquire` starts again. The container remembers the key it started with: a test with a different one gets a
44
+ * new container, which replaces it.
36
45
  */
37
46
  export declare class FileContainer<C extends SharedContainer> {
38
47
  #private;
39
48
  /** The file's running container, if one has started and not been discarded. */
40
49
  get current(): C | undefined;
41
50
  /**
42
- * The file's container for a test whose feature flags key is `key` (`featureFlagsKey`): the running one, or the
43
- * one starting, when either has the same key, or one `start` starts. A running container with a different key is
51
+ * The file's container for a test whose container key is `key`: the running one, or the one starting, when either
52
+ * has the same key, or one `start` starts. A running container with a different key is
44
53
  * forgotten and ended first, and the new one replaces it; when that end fails, rejects saying so, leaving no
45
54
  * container. A start in flight with a different key is waited for, its failure ignored, then treated the same way.
46
55
  * Throws after `close`.
47
56
  */
48
- acquire(start: StartFileContainer<C>, key: string): Promise<AcquiredContainer<C>>;
57
+ acquire(start: StartFileContainer<C>, key: ContainerKey): Promise<AcquiredContainer<C>>;
49
58
  /**
50
59
  * Replaces `stopped`, the file's container, which Testserver has stopped, with one `start` starts for a test whose
51
- * feature flags key is `key`: forgets it, ends it (Testserver answers the end of a stopped container's test id),
60
+ * container key is `key`: forgets it, ends it (Testserver answers the end of a stopped container's test id),
52
61
  * then starts the new one. When the end fails, rejects saying so, leaving no container. Throws after `close`.
53
62
  */
54
- replaceStopped(stopped: C, start: StartFileContainer<C>, key: string): Promise<AcquiredContainer<C>>;
63
+ replaceStopped(stopped: C, start: StartFileContainer<C>, key: ContainerKey): Promise<AcquiredContainer<C>>;
55
64
  /** Forgets `container` if it is the file's, then ends it. An end that fails throws, but it is forgotten all the same. */
56
65
  discard(container: C): Promise<void>;
57
66
  /**
@@ -79,9 +88,9 @@ export interface ContainerRequest<C extends SharedContainer> {
79
88
  * request a fault rule on the test's proxy forwarded, asked in the failure handler.
80
89
  */
81
90
  readonly testserverFailed: () => boolean;
82
- /** The canonical key of the test's feature flags (`featureFlagsKey`), which the file's container must match. */
83
- readonly featureFlagsKey: string;
84
- /** Starts the file's container, in `'file'` scope, saying whether it replaces one with other feature flags. */
91
+ /** The test's container key, its feature flags' and its `recordHeaders` list's, which the file's container must match. */
92
+ readonly containerKey: ContainerKey;
93
+ /** Starts the file's container, in `'file'` scope, saying why it replaces the file's container when it does. */
85
94
  readonly startShared: StartFileContainer<C>;
86
95
  /** Starts the test's own container, in `'test'` scope. */
87
96
  readonly startOwn: () => Promise<C>;
@@ -96,7 +105,7 @@ export interface ContainerRequest<C extends SharedContainer> {
96
105
  * container log read there, before the container ends; one that fails later is reported without it.
97
106
  *
98
107
  * In `'file'` scope, hands the test the file's container, starting it if need be, or replacing it when its feature
99
- * flags differ from the test's. A test that aborts while it is starting never gets it, but the container stays the
108
+ * 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
100
109
  * file's, for its next test. A test handed a container an earlier test used notes its container log's last record, so
101
110
  * its report can print only the records after it. When that note finds Testserver has stopped the container
102
111
  * (`container-stopped`), as its idle eviction does between tests, the test gets a new container in its place, before
@@ -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,15 +9,16 @@ 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
13
- * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
14
- * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
15
- * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
16
- * 200)`. A status that fails the call (a record's `failure`) reads with why, such as `503 (the container stopped: …)`,
17
- * and an answer that broke off after its status with `then failed`, such as `200, then failed (aborted)`.
12
+ * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
13
+ * duration, and any session id from `sessionHeader` (both read from its `requestHeaders`, ignoring `<redacted>`),
14
+ * such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts with its external
15
+ * service, such as `external github POST /scenarios → 204, …`. A proxy record whose exchange was still open reads
16
+ * `open`, its duration counted to the read. A proxy record of a request a fault rule matched tags its result with the
17
+ * action and what Testserver answered, such as `500 (fault: replace, Testserver 200)`. A status that fails the call
18
+ * (a record's `failure`) reads with why, such as `503 (the container stopped: …)`, and an answer that broke off after
19
+ * its status with `then failed`, such as `200, then failed (aborted)`.
18
20
  */
19
- export declare function describeRequest(request: RequestLine): string;
21
+ export declare function describeRequest(request: RequestLine, sessionHeader?: string): string;
20
22
  /**
21
23
  * A recorded body on one line, cut at `BODY_REPORT_CHARS`: JSON compact, a form as its encoded fields, text
22
24
  * quoted, and an omitted body as its note, such as `[binary, 5 bytes, image/png]`.
@@ -141,7 +143,7 @@ export declare function sharedContainerFailureReport(container: Omit<ContainerRe
141
143
  * What a verbose run prints as the proxy records a request: the request line with its bodies, as a failure report
142
144
  * would show it, naming the test id.
143
145
  */
144
- export declare function proxyRequestReport(testId: string, request: ProxyRequestRecord, redact: Redact): string;
146
+ export declare function proxyRequestReport(testId: string, request: ProxyRequestRecord, redact: Redact, sessionHeader?: string): string;
145
147
  /**
146
148
  * One warmup as a failure report's line: how many services, how long, and each that failed with why, such as
147
149
  * `warmup: 3 services in 2140ms, 1 failed (api-projects: HTTP 500: …)`.
@@ -149,7 +151,7 @@ export declare function proxyRequestReport(testId: string, request: ProxyRequest
149
151
  export declare function describeWarmup(warmup: ServiceWarmup, redact: Redact): string;
150
152
  /**
151
153
  * 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
154
+ * 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
155
  * has, any warmup after it with the services that failed, and its test id, such as `storm: started a container for
154
156
  * the file a.test.ts in 812ms, 1 feature flag, warmed 3 services in 2140ms (1 failed: api-projects), test id ts-…`.
155
157
  */
@@ -160,7 +162,7 @@ export declare function containerStartReport(start: {
160
162
  readonly testId: string;
161
163
  readonly featureFlags?: FeatureFlags;
162
164
  /** Why it replaced the file's container, when it did. */
163
- readonly replaced?: "feature-flags" | "stopped";
165
+ readonly replaced?: ReplacedFor;
164
166
  readonly warmup?: {
165
167
  readonly ms: number;
166
168
  readonly warmup: ServiceWarmup;
@@ -172,7 +174,7 @@ export declare function containerStartReport(start: {
172
174
  * container's, so a secret the proxy's own redaction can't know of, such as another seeded token, reads `<token>`
173
175
  * too).
174
176
  */
175
- export declare function proxyFailureReport(testId: string, requests: readonly ProxyRequestRecord[], redact: Redact, faults?: readonly FaultHandle[]): string;
177
+ export declare function proxyFailureReport(testId: string, requests: readonly ProxyRequestRecord[], redact: Redact, faults?: readonly FaultHandle[], sessionHeader?: string): string;
176
178
  /**
177
179
  * Why a test fails when Testserver failed a request its proxy forwarded, naming each such request, through
178
180
  * `redact`; `undefined` when none did. Testserver failed a request a fault rule forwarded when it gave no answer, one