@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
@@ -16,7 +16,8 @@
16
16
  // and the types its lifecycle reads its options by (`ResolvedOptions`, `OptionSources`);
17
17
  // - how a driver is written: one `defineDriver` per driver (`driver.ts`), in its folder's `driver.ts`, which holds
18
18
  // what the launcher knows of one program that the command starts (`Driver`): its name, its program, its Context,
19
- // the argv that starts it, its plan step over its Context (`DriverPlanRequest`, `DriverPlanAnswer`) and its words,
19
+ // the argv that starts it, its plan step over its Context (`DriverPlanRequest`, `DriverPlanAnswer`), whether it
20
+ // counts only the test files unless asked (`DriverTestCount`) and its words,
20
21
  // its part of its command's help (`DriverHelp`), what its run's summary says to do next (`DriverHints`) and what its
21
22
  // two refusals say (`DriverRefusalWords`);
22
23
  // - each lifecycle point's input and answer (`lifecycle.ts`), the refusal a lifecycle point words where it refuses
@@ -11,13 +11,14 @@ export interface Setting<T> {
11
11
  readonly source: SettingSource;
12
12
  }
13
13
  /**
14
- * What a run counted before it started: `counted`, the tests `storm vitest`'s `vitest list` or `storm playwright`'s
15
- * `playwright test --list` lists and the files they are in; `not-counted` for a run that counts nothing, such as `storm
16
- * exec`'s, and for a command that plans no run, such as an extension's own command.
14
+ * What a run counted before it started: `counted`, the test files `storm vitest`'s `vitest list` or `storm
15
+ * playwright`'s `playwright test --list` lists, and the tests in them when the driver counted them too (`tests`, absent
16
+ * for a `storm vitest` run without `--count-tests`, which counts only the files); `not-counted` for a run that counts
17
+ * nothing, such as `storm exec`'s, and for a command that plans no run, such as an extension's own command.
17
18
  */
18
19
  export type RunTestPlan = {
19
20
  readonly kind: "counted";
20
- readonly tests: number;
21
+ readonly tests?: number;
21
22
  readonly files: number;
22
23
  } | {
23
24
  readonly kind: "not-counted";
@@ -50,7 +51,7 @@ export interface FlagHelp {
50
51
  * value, which a transform may normalize, such as a URL to a short form. Its error messages follow
51
52
  * the option's key path, `must be …, not …` (`mustBe`), so the file and the flag say the same.
52
53
  * - `default`: the value when neither the file nor a flag gives one; or a function of the planned run, such as one
53
- * that sizes the option from the tests `storm vitest` counted, called once as the options resolve, whose value
54
+ * that sizes the option from the test files `storm vitest` counted, called once as the options resolve, whose value
54
55
  * `schema` checks too. An option whose default is a function takes a string, number or boolean, and the run's test
55
56
  * plan lists it with its value and where that came from.
56
57
  * - `required`: a resource without this option is a problem.
@@ -1,4 +1,4 @@
1
- import { type ApiRequestRecord, type RecordedBody, type RequestOutcome } from "../records/index.ts";
1
+ import { type ApiRequestRecord, type RecordedBody, type RecordedHeaders, type RequestOutcome } from "../records/index.ts";
2
2
  import { type TestserverFailure } from "../testserver/index.ts";
3
3
  /**
4
4
  * A request body `container.fetch` takes: one it can read whole at once, before it sends anything. A stream or an
@@ -13,9 +13,8 @@ export type ContainerRequestInit = Omit<RequestInit, "body"> & {
13
13
  export declare function apiRequestRecord(request: {
14
14
  readonly method: string;
15
15
  readonly target: string;
16
- readonly authorization: boolean;
16
+ readonly requestHeaders: RecordedHeaders;
17
17
  readonly requestBody: RecordedBody | undefined;
18
- readonly responseBody?: RecordedBody | undefined;
19
18
  readonly startedAt: number;
20
19
  readonly durationMs: number;
21
20
  readonly outcome: RequestOutcome;
@@ -1,4 +1,4 @@
1
- import { splitTarget } from "../records/index.js";
1
+ import { splitTarget, } from "../records/index.js";
2
2
  import { excerpt, httpFailure, TEST_ID_HEADER } from "../testserver/index.js";
3
3
  /** Statuses whose answer has no body, so a `Response` can't be built with one. */
4
4
  const NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
@@ -8,9 +8,8 @@ export function apiRequestRecord(request) {
8
8
  method: request.method,
9
9
  url: request.target,
10
10
  ...splitTarget(request.target),
11
- authorization: request.authorization,
11
+ requestHeaders: request.requestHeaders,
12
12
  ...(request.requestBody === undefined ? {} : { requestBody: request.requestBody }),
13
- ...(request.responseBody === undefined ? {} : { responseBody: request.responseBody }),
14
13
  startedAt: request.startedAt,
15
14
  durationMs: request.durationMs,
16
15
  ...request.outcome,
@@ -1,5 +1,5 @@
1
1
  import { type FactoryCall, type FactoryOptions } from "../factories/index.ts";
2
- import type { ApiRequestRecord, ExternalCallRecord } from "../records/index.ts";
2
+ import { type ApiRequestRecord, type ExternalCallRecord } from "../records/index.ts";
3
3
  import { type Clock, type ExternalServiceId, type GitProviderId, type SetupScriptId, type TestserverServiceId } from "../testserver/index.ts";
4
4
  import { type ContainerRequestInit } from "./api-request.ts";
5
5
  import { type ExternalService, type GitProvider, type SetupCall } from "./external.ts";
@@ -48,6 +48,15 @@ export interface ContainerOptions {
48
48
  * know whether a service had already started.
49
49
  */
50
50
  readonly featureFlags?: FeatureFlags;
51
+ /**
52
+ * The headers whose values its API request and external call records show as sent, in requests and responses,
53
+ * besides `DEFAULT_RECORD_HEADERS` (such as `content-type`), which it adds to: such as `["x-trace"]`; names are
54
+ * compared without regard to case. Every other header's value reads
55
+ * `<redacted>`, but `authorization` and `proxy-authorization`, which show their scheme, and `cookie` and
56
+ * `set-cookie`, which show each cookie's name; those four can't be listed. By default none beyond the defaults. A bad list is a
57
+ * `TypeError` before anything is sent.
58
+ */
59
+ readonly recordHeaders?: readonly string[];
51
60
  }
52
61
  /** How one service answered a warmup: started, or why not, in `error`, redacted with the container's `redact`. */
53
62
  export type ServiceWarmupOutcome = {
@@ -156,7 +165,8 @@ export interface Container {
156
165
  /**
157
166
  * `text` with every token secret the container has seen replaced by `<token>`: each string under a token field in
158
167
  * its factory calls' inputs, options and responses, its API requests' and external calls' JSON bodies and its setup
159
- * scripts' return values, and each bearer token its API requests and external calls sent. For printing what
168
+ * scripts' return values, and the credentials of each `authorization` header its API requests and external calls
169
+ * sent, whatever the scheme. For printing what
160
170
  * Testserver logged.
161
171
  */
162
172
  redact(text: string): string;
@@ -1,4 +1,5 @@
1
1
  import { buildUntypedFactory, } from "../factories/index.js";
2
+ import { checkRecordHeaders } from "../records/index.js";
2
3
  import { checkTestId, describeFailure, generateTestId, redactFailure, routes, systemClock, TestserverCallError, testserverEndpoint, unroutable, } from "../testserver/index.js";
3
4
  import { checkContainerRequest, hasNullBody, refusedAnswer } from "./api-request.js";
4
5
  import { checkExternalServiceId, checkGitProviderId, checkSetupScriptId, failedAnswer, gitProviderLogs, } from "./external.js";
@@ -55,6 +56,7 @@ export async function startContainer(options, context = liveSdkContext()) {
55
56
  checkTestId(options.testId);
56
57
  if (options.featureFlags !== undefined)
57
58
  checkFeatureFlags(options.featureFlags);
59
+ const recordHeaders = checkRecordHeaders(options.recordHeaders);
58
60
  const featureFlags = normalizeFeatureFlags(options.featureFlags ?? {});
59
61
  const { testserverUrl } = options;
60
62
  const firstStartedAt = context.clock.now();
@@ -70,7 +72,7 @@ export async function startContainer(options, context = liveSdkContext()) {
70
72
  });
71
73
  if (started.ok) {
72
74
  await setFeatureFlags(context, { testserverUrl, testId }, featureFlags);
73
- return new RunningContainer(context, testserverUrl, testId, started.info, featureFlags);
75
+ return new RunningContainer(context, { testserverUrl, testId, info: started.info, featureFlags, recordHeaders });
74
76
  }
75
77
  first ??= started.failure;
76
78
  const startError = new TestserverCallError({
@@ -193,18 +195,19 @@ export async function withContainer(options, body, context) {
193
195
  }
194
196
  class RunningContainer {
195
197
  #context;
196
- #recorder = new ContainerRecorder();
198
+ #recorder;
197
199
  #ended = false;
198
200
  testserverUrl;
199
201
  testId;
200
202
  info;
201
203
  featureFlags;
202
- constructor(context, testserverUrl, testId, info, featureFlags) {
204
+ constructor(context, started) {
203
205
  this.#context = context;
204
- this.testserverUrl = testserverUrl;
205
- this.testId = testId;
206
- this.info = info;
207
- this.featureFlags = featureFlags;
206
+ this.#recorder = new ContainerRecorder(started.recordHeaders);
207
+ this.testserverUrl = started.testserverUrl;
208
+ this.testId = started.testId;
209
+ this.info = started.info;
210
+ this.featureFlags = started.featureFlags;
208
211
  }
209
212
  get factoryCalls() {
210
213
  return this.#recorder.factoryCalls;
@@ -1,5 +1,5 @@
1
1
  import type { FactoryCall } from "../factories/index.ts";
2
- import { type ApiRequestRecord, type ExternalCallRecord, type RequestOutcome } from "../records/index.ts";
2
+ import { type ApiRequestRecord, type ExternalCallRecord } from "../records/index.ts";
3
3
  import { type TestserverFailure } from "../testserver/index.ts";
4
4
  import type { ServiceWarmup } from "./container.ts";
5
5
  import type { SetupCall } from "./external.ts";
@@ -11,7 +11,10 @@ export type Channel = {
11
11
  readonly kind: "external";
12
12
  readonly externalId: string;
13
13
  };
14
- /** What an exchange sent, as its record keeps it: `target` is the path the caller gave, with any query. */
14
+ /**
15
+ * What an exchange sent, as its record keeps it: `target` is the path the caller gave, with any query, and `headers`
16
+ * the caller's, without the test id, which the gateway adds.
17
+ */
15
18
  export interface SentExchange {
16
19
  readonly method: string;
17
20
  readonly target: string;
@@ -19,12 +22,30 @@ export interface SentExchange {
19
22
  readonly body: Uint8Array;
20
23
  readonly startedAt: number;
21
24
  }
25
+ /**
26
+ * How an exchange ended, as `RecordedExchange.end` takes it: `RequestOutcome` without the answer's headers and body,
27
+ * which `RecordedExchange.answered` keeps.
28
+ */
29
+ export type ExchangeOutcome = {
30
+ readonly status: number;
31
+ readonly error?: string;
32
+ readonly failure?: TestserverFailure;
33
+ } | {
34
+ readonly error: string;
35
+ readonly failure?: TestserverFailure;
36
+ };
22
37
  /** One exchange the recorder has begun: what it was answered, then how it ended, which records it once. */
23
38
  export interface RecordedExchange {
24
- /** Keeps the answer's body, and learns the token fields of a JSON one, before anything reads the answer. */
39
+ /**
40
+ * Keeps the answer's headers and body, and learns the token fields of a JSON body, before anything reads the
41
+ * answer.
42
+ */
25
43
  answered(answer: ContainerAnswer): void;
26
- /** Records the exchange, ended at `now` on the SDK clock. Only the first call records. */
27
- end(outcome: RequestOutcome, now: number): void;
44
+ /**
45
+ * Records the exchange, ended at `now` on the SDK clock, with the answer `answered` kept beside a status, or no
46
+ * headers when it kept none. Only the first call records.
47
+ */
48
+ end(outcome: ExchangeOutcome, now: number): void;
28
49
  }
29
50
  /** One setup script run, as the container sent it: the script's raw return value, or why it failed. */
30
51
  export interface SetupRun {
@@ -45,6 +66,7 @@ export interface SetupRun {
45
66
  */
46
67
  export declare class ContainerRecorder {
47
68
  #private;
69
+ constructor(recordHeaders?: ReadonlySet<string>);
48
70
  get factoryCalls(): readonly FactoryCall[];
49
71
  get apiRequests(): readonly ApiRequestRecord[];
50
72
  get externalCalls(): readonly ExternalCallRecord[];
@@ -58,8 +80,8 @@ export declare class ContainerRecorder {
58
80
  /** Keeps a setup call's record, its return value with every token field reading `<token>`, once it has learned them. */
59
81
  setupCall(run: SetupRun): void;
60
82
  /**
61
- * Begins the record of one exchange on `channel`: learns the bearer token it sends and keeps its request body, before
62
- * it is sent, so `redact` covers a refused answer's excerpt.
83
+ * Begins the record of one exchange on `channel`: learns the credentials of the `authorization` header it sends,
84
+ * whatever its scheme, and keeps its request body, before it is sent, so `redact` covers a refused answer's excerpt.
63
85
  */
64
86
  begin(channel: Channel, sent: SentExchange): RecordedExchange;
65
87
  /** Keeps a warmup's record, each failed service's error redacted, and returns it. */
@@ -1,4 +1,4 @@
1
- import { bearerToken, decodeBody, incomingHeaders, RECORDED_BODY_CAP_BYTES, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "../records/index.js";
1
+ import { decodeBody, authorizationSecret, checkRecordHeaders, incomingHeaders, RECORDED_BODY_CAP_BYTES, recordedHeaders, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "../records/index.js";
2
2
  import { redactFailure } from "../testserver/index.js";
3
3
  import { apiRequestRecord } from "./api-request.js";
4
4
  /**
@@ -12,6 +12,11 @@ export class ContainerRecorder {
12
12
  #setupCalls = [];
13
13
  #warmups = [];
14
14
  #secrets = new Set();
15
+ /** The lowercased names of the headers whose values its records show as sent, the defaults among them. */
16
+ #recordHeaders;
17
+ constructor(recordHeaders = checkRecordHeaders(undefined)) {
18
+ this.#recordHeaders = recordHeaders;
19
+ }
15
20
  get factoryCalls() {
16
21
  return [...this.#factoryCalls];
17
22
  }
@@ -51,31 +56,38 @@ export class ContainerRecorder {
51
56
  this.#setupCalls.push({ scriptId, outcome: { ok: true, response }, startedAt, durationMs });
52
57
  }
53
58
  /**
54
- * Begins the record of one exchange on `channel`: learns the bearer token it sends and keeps its request body, before
55
- * it is sent, so `redact` covers a refused answer's excerpt.
59
+ * Begins the record of one exchange on `channel`: learns the credentials of the `authorization` header it sends,
60
+ * whatever its scheme, and keeps its request body, before it is sent, so `redact` covers a refused answer's excerpt.
56
61
  */
57
62
  begin(channel, sent) {
58
63
  const authorization = sent.headers.find(([name]) => name.toLowerCase() === "authorization")?.[1];
59
- const bearer = bearerToken(authorization);
60
- if (bearer !== undefined && bearer !== "")
61
- this.#secrets.add(bearer);
62
- const requestBody = this.#kept(sent.body, sent.headers, bearer);
63
- let responseBody;
64
+ const credentials = authorizationSecret(authorization);
65
+ if (credentials !== undefined)
66
+ this.#secrets.add(credentials);
67
+ const redaction = { secret: credentials, shown: this.#recordHeaders };
68
+ const requestHeaders = recordedHeaders(sent.headers, redaction);
69
+ const requestBody = this.#kept(sent.body, sent.headers, credentials);
70
+ let answered;
64
71
  let ended = false;
65
72
  return {
66
73
  answered: (answer) => {
67
- responseBody = this.#kept(answer.body, answer.headers, bearer);
74
+ const responseBody = this.#kept(answer.body, answer.headers, credentials);
75
+ answered = {
76
+ responseHeaders: recordedHeaders(answer.headers, redaction),
77
+ ...(responseBody === undefined ? {} : { responseBody }),
78
+ };
68
79
  },
69
- end: (outcome, now) => {
80
+ end: (ending, now) => {
70
81
  if (ended)
71
82
  return;
72
83
  ended = true;
84
+ // A status outcome carries the answer `answered` kept; a test that ends one unanswered gets no headers.
85
+ const outcome = "status" in ending ? { ...ending, responseHeaders: {}, ...answered } : ending;
73
86
  const fields = apiRequestRecord({
74
87
  method: sent.method,
75
88
  target: sent.target,
76
- authorization: authorization !== undefined,
89
+ requestHeaders,
77
90
  requestBody,
78
- responseBody,
79
91
  startedAt: sent.startedAt,
80
92
  durationMs: now - sent.startedAt,
81
93
  outcome,
@@ -105,14 +117,14 @@ export class ContainerRecorder {
105
117
  return redactFailure(failure, (text) => this.redact(text));
106
118
  }
107
119
  /** A body as its record keeps it: decoded, capped and redacted, the strings under its JSON token fields learned. */
108
- #kept(bytes, headers, bearer) {
120
+ #kept(bytes, headers, credentials) {
109
121
  if (bytes.byteLength === 0)
110
122
  return undefined;
111
123
  const raw = bytes.byteLength > RECORDED_BODY_CAP_BYTES ? undefined : bytes;
112
124
  const decoded = decodeBody(raw, bytes.byteLength, incomingHeaders(headers));
113
125
  if (decoded.kind === "json")
114
126
  this.#learn(decoded.value);
115
- return redactBody(decoded, bearer);
127
+ return redactBody(decoded, credentials);
116
128
  }
117
129
  #learn(value) {
118
130
  for (const secret of tokenSecrets(value))
@@ -1,5 +1,5 @@
1
1
  export { type Container, type ContainerInfo, type ContainerLogOptions, type ContainerLogRecord, type ContainerOptions, type ContainerRequestBody, type ContainerRequestInit, type ExternalService, FEATURE_FLAG_CLIENTS, type FeatureFlagClient, type FeatureFlags, featureFlagsKey, type FeatureFlagValue, type GitProvider, type GitProviderRequestLog, type GitProviderScenario, liveSdkContext, type SdkContext, type ServiceWarmup, type ServiceWarmupOutcome, type SetupCall, startContainer, withContainer, } from "./container/index.ts";
2
2
  export { type FactoryCall, FactoryInputError, type FactoryInputPart, type FactoryOptions } from "./factories/index.ts";
3
3
  export { type ContainerProxy, type FaultHandle, type FaultResponse, type FaultRule, type FaultUpstream, isOpenRecord, type OpenRequestOutcome, type ProxyFault, type ProxyOptions, type ProxyRequestOutcome, type ProxyRequestRecord, type ProxyTarget, startProxy, withProxy, } from "./proxy/index.ts";
4
- export { type ApiRequestRecord, type ExternalCallRecord, RECORDED_BODY_CAP_BYTES, type RecordedBody, REDACTED, redactSecrets, redactTokenFields, } from "./records/index.ts";
4
+ export { type ApiRequestRecord, DEFAULT_RECORD_HEADERS, type ExternalCallRecord, RECORDED_BODY_CAP_BYTES, type RecordedBody, type RecordedHeaders, recordHeadersKey, REDACTED, REDACTED_HEADER, redactSecrets, redactTokenFields, } from "./records/index.ts";
5
5
  export { APP_SERVICE_IDS, APP_SERVICE_IDS_CHECKED_AGAINST, describeFailure, EXTERNAL_IDS_CHECKED_AGAINST, EXTERNAL_SERVICE_IDS, type ExternalServiceId, GIT_PROVIDER_IDS, type GitProviderId, type KnownExternalServiceId, type KnownSetupScriptId, type KnownTestserverServiceId, MAX_TEST_ID_LENGTH, SERVICE_IDS_CHECKED_AGAINST, SETUP_SCRIPT_IDS, type SetupScriptId, TESTSERVER_SERVICE_IDS, TESTSERVER_TRANSIENT_FAILURE, type TestserverServiceId, TEST_ID_HEADER, TestIdError, TestserverCallError, type TestserverFailure, } from "./testserver/index.ts";
@@ -6,5 +6,5 @@
6
6
  export { FEATURE_FLAG_CLIENTS, featureFlagsKey, liveSdkContext, startContainer, withContainer, } from "./container/index.js";
7
7
  export { FactoryInputError } from "./factories/index.js";
8
8
  export { isOpenRecord, startProxy, withProxy, } from "./proxy/index.js";
9
- export { RECORDED_BODY_CAP_BYTES, REDACTED, redactSecrets, redactTokenFields, } from "./records/index.js";
9
+ export { DEFAULT_RECORD_HEADERS, RECORDED_BODY_CAP_BYTES, recordHeadersKey, REDACTED, REDACTED_HEADER, redactSecrets, redactTokenFields, } from "./records/index.js";
10
10
  export { APP_SERVICE_IDS, APP_SERVICE_IDS_CHECKED_AGAINST, describeFailure, EXTERNAL_IDS_CHECKED_AGAINST, EXTERNAL_SERVICE_IDS, GIT_PROVIDER_IDS, MAX_TEST_ID_LENGTH, SERVICE_IDS_CHECKED_AGAINST, SETUP_SCRIPT_IDS, TESTSERVER_SERVICE_IDS, TESTSERVER_TRANSIENT_FAILURE, TEST_ID_HEADER, TestIdError, TestserverCallError, } from "./testserver/index.js";
@@ -1,11 +1,15 @@
1
1
  import type { ClientRequest, IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http";
2
- import { BodyCapture, type RecordedBody, type RequestOutcome } from "../records/index.ts";
2
+ import { BodyCapture, type HeaderEntries, type RecordedHeaders, type RequestOutcome } from "../records/index.ts";
3
3
  import type { FaultRule, FaultUpstream } from "./faults.ts";
4
4
  import { type ProxyRequestRecord } from "./records.ts";
5
- /** Testserver's status and headers once they arrive, and its body so far. */
5
+ /**
6
+ * Testserver's status and headers once they arrive, and its body so far. `headers` decode the body, and
7
+ * `recordedHeaders` are what a record keeps of them: less hop-by-hop headers, redacted.
8
+ */
6
9
  export interface UpstreamAnswer {
7
10
  readonly status: number;
8
11
  readonly headers: IncomingHttpHeaders;
12
+ readonly recordedHeaders: RecordedHeaders;
9
13
  readonly body: BodyCapture;
10
14
  }
11
15
  /** What an exchange needs of its proxy. */
@@ -16,6 +20,8 @@ export interface ExchangeDeps {
16
20
  send(request: IncomingMessage, onAnswer: (answer: IncomingMessage) => void): ClientRequest;
17
21
  /** Hears each record as its exchange ends; what it throws is dropped. */
18
22
  readonly onRequest?: ((record: ProxyRequestRecord) => void) | undefined;
23
+ /** The lowercased names of the headers whose values its records show as sent (`checkRecordHeaders`). */
24
+ readonly recordHeaders: ReadonlySet<string>;
19
25
  }
20
26
  /**
21
27
  * One request the proxy received and the response it sends: its record, open until the exchange ends and set once
@@ -28,20 +34,28 @@ export declare class Exchange {
28
34
  readonly request: IncomingMessage;
29
35
  readonly response: ServerResponse;
30
36
  readonly method: string;
31
- /** The request's bearer token, which its record's bodies redact. */
32
- readonly bearer: string | undefined;
37
+ /**
38
+ * The credentials of the request's `authorization` header, whatever its scheme, which its record's bodies and
39
+ * shown headers redact (`authorizationSecret`: none when shorter than `MIN_CREDENTIAL_CHARS`).
40
+ */
41
+ readonly credentials: string | undefined;
33
42
  constructor(request: IncomingMessage, response: ServerResponse, deps: ExchangeDeps, faultAction: FaultRule["action"] | undefined);
34
43
  /** Whether its record has ended. */
35
44
  get ended(): boolean;
36
45
  /** Its record: the ended one once it ended, otherwise an open record as of now. */
37
46
  read(): ProxyRequestRecord;
47
+ /**
48
+ * `headers` as its record keeps them (`recordedHeaders`): shown as sent only when the proxy's `recordHeaders` names
49
+ * them, and redacted with its request's credentials.
50
+ */
51
+ recordedHeaders(headers: HeaderEntries): RecordedHeaders;
38
52
  /** Records it as ended by the proxy's close; does nothing once it has ended. */
39
53
  finalize(): void;
40
54
  /**
41
55
  * Ends its record with `outcome`, what the client got, and under a forwarding fault `upstream`, what Testserver
42
56
  * answered, then tells `onRequest`. Does nothing once it has ended.
43
57
  */
44
- record(outcome: RequestOutcome, responseBody?: RecordedBody, upstream?: FaultUpstream): void;
58
+ record(outcome: RequestOutcome, upstream?: FaultUpstream): void;
45
59
  /** Sends the request on to Testserver, its body still to be written; a hangup or close destroys it. */
46
60
  forward(onAnswer: (answer: IncomingMessage) => void): ClientRequest;
47
61
  /** Records that the client is being sent Testserver's answer, so a hangup or close records how far it got. */
@@ -50,6 +64,11 @@ export declare class Exchange {
50
64
  unreachable(error: Error, upstream?: FaultUpstream): void;
51
65
  /** Runs `step` after `delayMs`, at once for 0; the exchange's end cancels a pending one. */
52
66
  after(delayMs: number, step: () => void): void;
67
+ /**
68
+ * Records it as ended by `error` partway: with Testserver's status, headers and the body so far if its answer to
69
+ * the client began. Does nothing once it has ended.
70
+ */
71
+ breakOff(error: string): void;
53
72
  }
54
73
  /**
55
74
  * Forwards the request with no fault rule: Testserver's status and headers go to the client as they arrive, and both
@@ -1,5 +1,5 @@
1
- import { bearerToken, BodyCapture } from "../records/index.js";
2
- import { answeredOutcome, forwardableHeaders, proxyRecord, } from "./records.js";
1
+ import { authorizationSecret, BodyCapture, recordedHeaders, } from "../records/index.js";
2
+ import { answeredOutcome, forwardableHeaders, proxyRecord, rawHeaderPairs, } from "./records.js";
3
3
  /** The error of an exchange that was still open when its proxy closed. */
4
4
  const CLOSED_ERROR = "the proxy closed";
5
5
  /** The error of an exchange whose client closed its connection before the response ended. */
@@ -14,9 +14,14 @@ export class Exchange {
14
14
  request;
15
15
  response;
16
16
  method;
17
- /** The request's bearer token, which its record's bodies redact. */
18
- bearer;
17
+ /**
18
+ * The credentials of the request's `authorization` header, whatever its scheme, which its record's bodies and
19
+ * shown headers redact (`authorizationSecret`: none when shorter than `MIN_CREDENTIAL_CHARS`).
20
+ */
21
+ credentials;
19
22
  #target;
23
+ /** The request's headers as the client sent them, redacted. */
24
+ #requestHeaders;
20
25
  #startedAt;
21
26
  #deps;
22
27
  /** The action of the fault rule the request matched, if any, which its record names. */
@@ -38,10 +43,10 @@ export class Exchange {
38
43
  this.response = response;
39
44
  this.method = request.method ?? "GET";
40
45
  this.#target = request.url ?? "/";
41
- const authorization = request.headers.authorization;
42
- this.bearer = bearerToken(typeof authorization === "string" ? authorization : undefined);
43
- this.#startedAt = deps.now();
46
+ this.credentials = authorizationSecret(request.headers.authorization);
44
47
  this.#deps = deps;
48
+ this.#requestHeaders = this.recordedHeaders(rawHeaderPairs(request.rawHeaders));
49
+ this.#startedAt = deps.now();
45
50
  this.#faultAction = faultAction;
46
51
  request.on("data", (chunk) => this.#requestBody.push(chunk));
47
52
  request.on("end", () => {
@@ -52,7 +57,7 @@ export class Exchange {
52
57
  response.on("close", () => {
53
58
  if (response.writableFinished || this.ended)
54
59
  return;
55
- this.#breakOff(HANGUP_ERROR);
60
+ this.breakOff(HANGUP_ERROR);
56
61
  this.#outgoing?.destroy();
57
62
  });
58
63
  }
@@ -64,19 +69,26 @@ export class Exchange {
64
69
  read() {
65
70
  return this.#ended ?? this.#build({ open: true });
66
71
  }
72
+ /**
73
+ * `headers` as its record keeps them (`recordedHeaders`): shown as sent only when the proxy's `recordHeaders` names
74
+ * them, and redacted with its request's credentials.
75
+ */
76
+ recordedHeaders(headers) {
77
+ return recordedHeaders(headers, { secret: this.credentials, shown: this.#deps.recordHeaders });
78
+ }
67
79
  /** Records it as ended by the proxy's close; does nothing once it has ended. */
68
80
  finalize() {
69
- this.#breakOff(CLOSED_ERROR);
81
+ this.breakOff(CLOSED_ERROR);
70
82
  }
71
83
  /**
72
84
  * Ends its record with `outcome`, what the client got, and under a forwarding fault `upstream`, what Testserver
73
85
  * answered, then tells `onRequest`. Does nothing once it has ended.
74
86
  */
75
- record(outcome, responseBody, upstream) {
87
+ record(outcome, upstream) {
76
88
  if (this.#ended !== undefined)
77
89
  return;
78
90
  clearTimeout(this.#delay);
79
- const entry = this.#build(outcome, responseBody, upstream);
91
+ const entry = this.#build(outcome, upstream);
80
92
  this.#ended = entry;
81
93
  try {
82
94
  this.#deps.onRequest?.(entry);
@@ -96,7 +108,7 @@ export class Exchange {
96
108
  }
97
109
  /** Records a Testserver that couldn't be reached, with `upstream` under a forwarding fault, and answers with a 502. */
98
110
  unreachable(error, upstream) {
99
- this.record({ error: error.message }, undefined, upstream);
111
+ this.record({ error: error.message }, upstream);
100
112
  this.response.writeHead(502, { "content-type": "text/plain" });
101
113
  this.response.end(`testserver proxy: Testserver could not be reached: ${error.message}`);
102
114
  }
@@ -107,24 +119,28 @@ export class Exchange {
107
119
  else
108
120
  this.#delay = setTimeout(step, delayMs);
109
121
  }
110
- /** Records it as ended by `error` partway: with Testserver's status and the body so far if its answer began. */
111
- #breakOff(error) {
122
+ /**
123
+ * Records it as ended by `error` partway: with Testserver's status, headers and the body so far if its answer to
124
+ * the client began. Does nothing once it has ended.
125
+ */
126
+ breakOff(error) {
112
127
  if (this.#answered === undefined) {
113
128
  this.record({ error });
114
129
  return;
115
130
  }
116
- this.record({ status: this.#answered.status, error }, this.#answered.body.incomplete(this.#answered.headers));
131
+ const { status, headers, recordedHeaders: responseHeaders, body } = this.#answered;
132
+ const responseBody = body.incomplete(headers);
133
+ this.record({ status, responseHeaders, ...(responseBody === undefined ? {} : { responseBody }), error });
117
134
  }
118
- #build(outcome, responseBody, upstream) {
135
+ #build(outcome, upstream) {
119
136
  return proxyRecord({
120
137
  method: this.method,
121
138
  target: this.#target,
122
- headers: this.request.headers,
139
+ requestHeaders: this.#requestHeaders,
123
140
  startedAt: this.#startedAt,
124
141
  durationMs: this.#deps.now() - this.#startedAt,
125
142
  outcome,
126
143
  requestBody: this.#recordedRequestBody(),
127
- responseBody,
128
144
  fault: this.#faultAction === undefined
129
145
  ? undefined
130
146
  : { action: this.#faultAction, ...(upstream === undefined ? {} : { upstream }) },
@@ -133,7 +149,7 @@ export class Exchange {
133
149
  #recordedRequestBody() {
134
150
  if (!this.#requestEnded)
135
151
  return this.#requestBody.incomplete(this.request.headers);
136
- this.#wholeRequestBody ??= { body: this.#requestBody.complete(this.request.headers, this.bearer) };
152
+ this.#wholeRequestBody ??= { body: this.#requestBody.complete(this.request.headers, this.credentials) };
137
153
  return this.#wholeRequestBody.body;
138
154
  }
139
155
  }
@@ -146,18 +162,20 @@ export function passThrough(exchange) {
146
162
  const { request, response } = exchange;
147
163
  const outgoing = exchange.forward((answer) => {
148
164
  const status = answer.statusCode ?? 502;
149
- response.writeHead(status, forwardableHeaders(answer.headers));
165
+ const forwarded = forwardableHeaders(answer.headers);
166
+ response.writeHead(status, forwarded);
150
167
  const responseBody = new BodyCapture();
151
- exchange.answering({ status, headers: answer.headers, body: responseBody });
168
+ const headers = exchange.recordedHeaders(Object.entries(forwarded));
169
+ exchange.answering({ status, headers: answer.headers, recordedHeaders: headers, body: responseBody });
152
170
  answer.on("data", (chunk) => responseBody.push(chunk));
153
171
  // Registered before `pipe`, whose own `end` listener ends the client's response: the record is in
154
172
  // `requests` before the client sees its answer end.
155
173
  answer.on("end", () => {
156
- const recorded = responseBody.complete(answer.headers, exchange.bearer);
157
- exchange.record(answeredOutcome(status, recorded), recorded);
174
+ const recorded = responseBody.complete(answer.headers, exchange.credentials);
175
+ exchange.record(answeredOutcome(status, headers, recorded));
158
176
  });
159
177
  answer.on("error", (error) => {
160
- exchange.record({ status, error: error.message }, responseBody.incomplete(answer.headers));
178
+ exchange.breakOff(error.message);
161
179
  response.destroy();
162
180
  });
163
181
  answer.pipe(response);
@@ -167,7 +185,7 @@ export function passThrough(exchange) {
167
185
  if (response.destroyed && exchange.ended)
168
186
  return;
169
187
  if (response.headersSent) {
170
- exchange.record({ status: response.statusCode, error: error.message });
188
+ exchange.breakOff(error.message);
171
189
  response.destroy();
172
190
  return;
173
191
  }
@@ -1,5 +1,5 @@
1
1
  import { BodyCapture } from "../records/index.js";
2
- import { answeredOutcome } from "./records.js";
2
+ import { answeredOutcome, forwardableHeaders } from "./records.js";
3
3
  /** The error of an exchange a `reset` fault rule ended before the proxy forwarded its request. */
4
4
  const RESET_BEFORE_ERROR = "the proxy injected a reset before forwarding";
5
5
  /** The error of an exchange a `reset` fault rule ended after Testserver answered: a lost response. */
@@ -49,7 +49,7 @@ export function applyFault(exchange, rule) {
49
49
  function act(exchange, rule, upstream) {
50
50
  if (rule.action === "reset") {
51
51
  const error = rule.when === "before-forward" ? RESET_BEFORE_ERROR : RESET_AFTER_ERROR;
52
- exchange.record({ error }, undefined, upstream);
52
+ exchange.record({ error }, upstream);
53
53
  exchange.request.socket.resetAndDestroy();
54
54
  return;
55
55
  }
@@ -57,7 +57,13 @@ function act(exchange, rule, upstream) {
57
57
  const body = exchange.method === "HEAD" ? Buffer.alloc(0) : rule.response.body;
58
58
  const fake = new BodyCapture();
59
59
  fake.push(body);
60
- exchange.record({ status: rule.response.status }, fake.complete(rule.response.headers, exchange.bearer), upstream);
60
+ const { headers } = rule.response;
61
+ const responseBody = fake.complete(headers, exchange.credentials);
62
+ exchange.record({
63
+ status: rule.response.status,
64
+ responseHeaders: exchange.recordedHeaders(Object.entries(headers)),
65
+ ...(responseBody === undefined ? {} : { responseBody }),
66
+ }, upstream);
61
67
  exchange.response.writeHead(rule.response.status, rule.response.headers);
62
68
  exchange.response.end(body);
63
69
  }
@@ -73,9 +79,10 @@ function forwardThenAct(exchange, rule, body) {
73
79
  if (exchange.ended || answer === undefined)
74
80
  return;
75
81
  const responseBody = answer.body.incomplete(answer.headers);
76
- exchange.record({ error: error.message }, undefined, {
82
+ exchange.record({ error: error.message }, {
77
83
  status: answer.status,
78
84
  error: error.message,
85
+ responseHeaders: answer.recordedHeaders,
79
86
  ...(responseBody === undefined ? {} : { responseBody }),
80
87
  });
81
88
  exchange.response.destroy();
@@ -83,16 +90,14 @@ function forwardThenAct(exchange, rule, body) {
83
90
  const outgoing = exchange.forward((incoming) => {
84
91
  const status = incoming.statusCode ?? 502;
85
92
  const captured = new BodyCapture();
86
- answer = { status, headers: incoming.headers, body: captured };
93
+ const recordedHeaders = exchange.recordedHeaders(Object.entries(forwardableHeaders(incoming.headers)));
94
+ answer = { status, headers: incoming.headers, recordedHeaders, body: captured };
87
95
  incoming.on("data", (chunk) => captured.push(chunk));
88
96
  incoming.on("end", () => {
89
97
  if (exchange.ended)
90
98
  return;
91
- const responseBody = captured.complete(incoming.headers, exchange.bearer);
92
- act(exchange, rule, {
93
- ...answeredOutcome(status, responseBody),
94
- ...(responseBody === undefined ? {} : { responseBody }),
95
- });
99
+ const responseBody = captured.complete(incoming.headers, exchange.credentials);
100
+ act(exchange, rule, answeredOutcome(status, recordedHeaders, responseBody));
96
101
  });
97
102
  incoming.on("error", brokenOff);
98
103
  });