@cnc-tools/storm 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.js +5 -1
- package/dist/bin/storm.js +6 -2
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-FK4RLDEK.js → chunk-27P2QSIM.js} +1 -1
- package/dist/chunks/{chunk-ODQHQJLE.js → chunk-5ED3IDUJ.js} +749 -1121
- package/dist/chunks/{chunk-FSP3SJ35.js → chunk-5TMHYH7G.js} +16 -46
- package/dist/chunks/{chunk-Y3BUNNRG.js → chunk-BFLYGMG3.js} +12 -7
- package/dist/chunks/{chunk-LQKNI3EG.js → chunk-BRUIATTR.js} +6 -6
- package/dist/chunks/{chunk-RYRJNHL7.js → chunk-HOKDKP5A.js} +3 -9
- package/dist/chunks/{chunk-SXW6XN4R.js → chunk-IVRRGGCD.js} +60 -20
- package/dist/chunks/{chunk-TMQQYHUX.js → chunk-QBR5VHJ7.js} +1 -1
- package/dist/chunks/{chunk-YT5OROR7.js → chunk-RA4L2ACU.js} +12 -2
- package/dist/chunks/{chunk-TEEZL3GA.js → chunk-RKONDLPS.js} +17 -71
- package/dist/chunks/{chunk-IYM44FUX.js → chunk-UC6DULWY.js} +2 -2
- package/dist/chunks/{chunk-4XT5RC5T.js → chunk-XPCUINWS.js} +6 -42
- package/dist/chunks/{chunk-U7M3ZB3Z.js → chunk-YBPTMJUM.js} +123 -180
- package/dist/chunks/{chunk-ISGQJIQM.js → chunk-Z5OXOZD3.js} +125 -83
- package/dist/chunks/{chunk-7D6LC5JY.js → chunk-ZH5R7W4A.js} +7 -39
- package/dist/chunks/{live-app-AZ5N5HBD.js → live-app-FBVWUUMT.js} +7 -7
- package/dist/commands/exec/command.d.ts +4 -90
- package/dist/commands/exec/command.js +15 -41
- package/dist/commands/exec/define-run-command.d.ts +19 -100
- package/dist/commands/exec/define-run-command.js +48 -15
- package/dist/commands/exec/driver-plan.d.ts +24 -16
- package/dist/commands/exec/driver-plan.js +34 -15
- package/dist/commands/exec/driver-refusals.js +7 -6
- package/dist/commands/exec/exec-words.d.ts +1 -1
- package/dist/commands/exec/exec-words.js +8 -2
- package/dist/commands/exec/final-results.d.ts +39 -0
- package/dist/commands/exec/final-results.js +29 -0
- package/dist/commands/exec/live-view.js +18 -22
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/outcomes.d.ts +15 -109
- package/dist/commands/exec/outcomes.js +25 -39
- package/dist/commands/exec/plan-run.d.ts +11 -3
- package/dist/commands/exec/plan-run.js +3 -2
- package/dist/commands/exec/progress.d.ts +3 -19
- package/dist/commands/exec/progress.js +16 -60
- package/dist/commands/exec/run-command.d.ts +5 -24
- package/dist/commands/exec/run-command.js +32 -84
- package/dist/commands/exec/run-metadata.d.ts +0 -6
- package/dist/commands/exec/run-metadata.js +2 -8
- package/dist/commands/exec/snapshot-text.d.ts +7 -16
- package/dist/commands/exec/snapshot-text.js +9 -49
- package/dist/commands/exec/test-plan.d.ts +2 -1
- package/dist/commands/exec/test-plan.js +13 -4
- package/dist/commands/exec/tests-summary.d.ts +2 -2
- package/dist/commands/exec/view.js +2 -12
- package/dist/commands/exec/worker-chart.d.ts +1 -1
- package/dist/commands/playwright/command.d.ts +12 -97
- package/dist/commands/playwright/command.js +14 -14
- package/dist/commands/playwright/metadata.js +2 -2
- package/dist/commands/runs/facts.d.ts +1 -37
- package/dist/commands/runs/facts.js +4 -36
- package/dist/commands/runs/list/command.d.ts +0 -72
- package/dist/commands/runs/list/command.js +6 -6
- package/dist/commands/runs/list/outcomes.d.ts +0 -36
- package/dist/commands/runs/logs/command.js +6 -6
- package/dist/commands/runs/show/command.d.ts +2 -74
- package/dist/commands/runs/show/command.js +16 -43
- package/dist/commands/runs/show/metadata.js +1 -1
- package/dist/commands/runs/show/outcomes.d.ts +1 -37
- package/dist/commands/runs/show/outcomes.js +8 -42
- package/dist/commands/snapshots/build/command.d.ts +14 -411
- package/dist/commands/snapshots/build/command.js +59 -234
- package/dist/commands/snapshots/build/metadata.js +10 -7
- package/dist/commands/snapshots/build/outcomes.d.ts +11 -241
- package/dist/commands/snapshots/build/outcomes.js +29 -196
- package/dist/commands/snapshots/list/command.d.ts +2 -36
- package/dist/commands/snapshots/list/command.js +20 -56
- package/dist/commands/snapshots/list/metadata.js +1 -1
- package/dist/commands/snapshots/list/outcomes.d.ts +2 -37
- package/dist/commands/snapshots/list/outcomes.js +13 -53
- package/dist/commands/vitest/command.d.ts +14 -98
- package/dist/commands/vitest/command.js +14 -14
- package/dist/commands/vitest/metadata.js +2 -2
- package/dist/config/resolve.d.ts +1 -1
- package/dist/config/resolve.js +2 -1
- package/dist/config/schema.d.ts +8 -0
- package/dist/config/schema.js +5 -4
- package/dist/core/events.d.ts +5 -6
- package/dist/core/run-state.d.ts +7 -29
- package/dist/core/run-state.js +3 -26
- package/dist/core/run.d.ts +6 -14
- package/dist/core/run.js +17 -28
- package/dist/extensions/playwright/driver.js +17 -10
- package/dist/extensions/testserver/commands/pool/create/command.js +4 -4
- package/dist/extensions/testserver/commands/pool/list/command.js +2 -2
- package/dist/extensions/testserver/definition.d.ts +1 -1
- package/dist/extensions/testserver/extension.d.ts +1 -1
- package/dist/extensions/testserver/options/rules.d.ts +3 -3
- package/dist/extensions/testserver/options/rules.js +5 -5
- package/dist/extensions/testserver/resource.d.ts +1 -1
- package/dist/extensions/testserver/vercel-cli/index.d.ts +1 -0
- package/dist/extensions/testserver/vercel-cli/index.js +1 -0
- package/dist/extensions/testserver/vercel-cli/report.js +5 -2
- package/dist/extensions/testserver/vercel-cli/session-id.d.ts +8 -0
- package/dist/extensions/testserver/vercel-cli/session-id.js +16 -0
- package/dist/extensions/testserver/vitest/config.d.ts +2 -2
- package/dist/extensions/testserver/vitest/config.js +2 -2
- package/dist/extensions/testserver/vitest/container-scope.d.ts +25 -16
- package/dist/extensions/testserver/vitest/container-scope.js +32 -13
- package/dist/extensions/testserver/vitest/diagnostics.d.ts +5 -4
- package/dist/extensions/testserver/vitest/diagnostics.js +15 -8
- package/dist/extensions/testserver/vitest/fixtures.d.ts +10 -1
- package/dist/extensions/testserver/vitest/fixtures.js +36 -10
- package/dist/extensions/testserver/vitest/types.d.ts +9 -0
- package/dist/extensions/vitest/driver.js +28 -14
- package/dist/extensions/vitest/plan/gateways.d.ts +28 -5
- package/dist/extensions/vitest/plan/gateways.js +2 -2
- package/dist/extensions/vitest/plan/list-output.d.ts +5 -0
- package/dist/extensions/vitest/plan/list-output.js +23 -9
- package/dist/extensions/vitest/plan/live/list-gateway.d.ts +3 -2
- package/dist/extensions/vitest/plan/live/list-gateway.js +77 -64
- package/dist/extensions/vitest/plan/plan-over.d.ts +19 -7
- package/dist/extensions/vitest/plan/plan-over.js +18 -7
- package/dist/extensions/vitest/plan/plan.d.ts +14 -5
- package/dist/extensions/vitest/plan/plan.js +23 -9
- package/dist/extensions.d.ts +2 -2
- package/dist/run-directory/index.d.ts +1 -1
- package/dist/run-directory/index.js +0 -1
- package/dist/run-directory/plan.d.ts +3 -2
- package/dist/run-directory/plan.js +6 -3
- package/dist/run-directory/recording.js +2 -2
- package/dist/run-directory/run-record.d.ts +18 -135
- package/dist/run-directory/run-record.js +8 -68
- package/dist/runner/build-snapshots.d.ts +50 -114
- package/dist/runner/build-snapshots.js +70 -159
- package/dist/runner/events.d.ts +4 -88
- package/dist/runner/gateways.d.ts +5 -23
- package/dist/runner/index.d.ts +5 -6
- package/dist/runner/index.js +1 -1
- package/dist/runner/live/snapshot-records.js +7 -18
- package/dist/runner/prepare.d.ts +11 -22
- package/dist/runner/prepare.js +6 -17
- package/dist/runner/ready.d.ts +16 -45
- package/dist/runner/ready.js +34 -59
- package/dist/runner/recipe.d.ts +5 -45
- package/dist/runner/recipe.js +0 -41
- package/dist/runner/sandboxed-command.d.ts +5 -3
- package/dist/runner/sandboxed-command.js +10 -4
- package/dist/runner/scope.d.ts +8 -25
- package/dist/runner/scope.js +4 -8
- package/dist/runner/session.d.ts +18 -65
- package/dist/runner/session.js +15 -83
- package/dist/runner/snapshot-build.d.ts +2 -2
- package/dist/runner/snapshot-cache.d.ts +22 -74
- package/dist/runner/snapshot-cache.js +15 -107
- package/dist/runner/snapshot-inspect.d.ts +9 -13
- package/dist/runner/snapshot-inspect.js +48 -57
- package/dist/runner/snapshot-key.d.ts +9 -14
- package/dist/runner/snapshot-key.js +15 -22
- package/dist/sdk/extension/driver.d.ts +32 -6
- package/dist/sdk/extension/driver.js +12 -2
- package/dist/sdk/extension/index.d.ts +1 -1
- package/dist/sdk/extension/index.js +2 -1
- package/dist/sdk/extension/resource-definition.d.ts +6 -5
- package/dist/vendor/testserver-sdk/container/api-request.d.ts +2 -3
- package/dist/vendor/testserver-sdk/container/api-request.js +2 -3
- package/dist/vendor/testserver-sdk/container/container.d.ts +12 -2
- package/dist/vendor/testserver-sdk/container/container.js +10 -7
- package/dist/vendor/testserver-sdk/container/recorder.d.ts +29 -7
- package/dist/vendor/testserver-sdk/container/recorder.js +26 -14
- package/dist/vendor/testserver-sdk/index.d.ts +1 -1
- package/dist/vendor/testserver-sdk/index.js +1 -1
- package/dist/vendor/testserver-sdk/proxy/exchange.d.ts +24 -5
- package/dist/vendor/testserver-sdk/proxy/exchange.js +43 -25
- package/dist/vendor/testserver-sdk/proxy/faulted-exchange.js +15 -10
- package/dist/vendor/testserver-sdk/proxy/faults.d.ts +6 -5
- package/dist/vendor/testserver-sdk/proxy/proxy.d.ts +10 -1
- package/dist/vendor/testserver-sdk/proxy/proxy.js +5 -3
- package/dist/vendor/testserver-sdk/proxy/records.d.ts +17 -17
- package/dist/vendor/testserver-sdk/proxy/records.js +18 -17
- package/dist/vendor/testserver-sdk/records/body.d.ts +7 -9
- package/dist/vendor/testserver-sdk/records/body.js +10 -15
- package/dist/vendor/testserver-sdk/records/headers.d.ts +79 -0
- package/dist/vendor/testserver-sdk/records/headers.js +162 -0
- package/dist/vendor/testserver-sdk/records/index.d.ts +2 -1
- package/dist/vendor/testserver-sdk/records/index.js +4 -2
- package/dist/vendor/testserver-sdk/records/records.d.ts +19 -10
- package/package.json +5 -4
- package/skills/overview.md +5 -5
- package/skills/read-run-output.md +8 -9
- package/dist/runner/snapshot-save.d.ts +0 -70
- package/dist/runner/snapshot-save.js +0 -160
- package/dist/runner/snapshot-start.d.ts +0 -25
- package/dist/runner/snapshot-start.js +0 -16
- package/skills/testserver-builds.md +0 -82
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FactoryCall } from "../factories/index.ts";
|
|
2
|
-
import { type ApiRequestRecord, type ExternalCallRecord
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
27
|
-
|
|
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
|
|
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 {
|
|
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
|
|
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
|
|
60
|
-
if (
|
|
61
|
-
this.#secrets.add(
|
|
62
|
-
const
|
|
63
|
-
|
|
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,
|
|
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: (
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
32
|
-
|
|
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,
|
|
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 {
|
|
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
|
-
/**
|
|
18
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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,
|
|
87
|
+
record(outcome, upstream) {
|
|
76
88
|
if (this.#ended !== undefined)
|
|
77
89
|
return;
|
|
78
90
|
clearTimeout(this.#delay);
|
|
79
|
-
const entry = this.#build(outcome,
|
|
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 },
|
|
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
|
-
/**
|
|
111
|
-
|
|
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
|
-
|
|
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,
|
|
135
|
+
#build(outcome, upstream) {
|
|
119
136
|
return proxyRecord({
|
|
120
137
|
method: this.method,
|
|
121
138
|
target: this.#target,
|
|
122
|
-
|
|
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.
|
|
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
|
-
|
|
165
|
+
const forwarded = forwardableHeaders(answer.headers);
|
|
166
|
+
response.writeHead(status, forwarded);
|
|
150
167
|
const responseBody = new BodyCapture();
|
|
151
|
-
|
|
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.
|
|
157
|
-
exchange.record(answeredOutcome(status,
|
|
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.
|
|
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.
|
|
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 },
|
|
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
|
-
|
|
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 },
|
|
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
|
-
|
|
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.
|
|
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
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestOutcome } from "../records/index.ts";
|
|
2
2
|
/**
|
|
3
3
|
* The response a `respond` or `replace` fault rule sends the client in place of Testserver's. The proxy adds no
|
|
4
4
|
* error format of its own, so a fake error body must match the real service's error format.
|
|
@@ -79,10 +79,11 @@ export interface ProxyFault {
|
|
|
79
79
|
*/
|
|
80
80
|
readonly upstream?: FaultUpstream;
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Testserver's answer under a forwarding fault, recorded as usual: beside a `status`, its headers (Testserver's less
|
|
84
|
+
* hop-by-hop headers) and body.
|
|
85
|
+
*/
|
|
86
|
+
export type FaultUpstream = RequestOutcome;
|
|
86
87
|
/** A rule checked by `checkRule`, its method upper-cased, its template split and its response serialized once. */
|
|
87
88
|
export type CheckedRule = {
|
|
88
89
|
readonly method: string;
|
|
@@ -21,6 +21,14 @@ export interface ProxyOptions {
|
|
|
21
21
|
* What it throws is dropped: it never touches the exchange.
|
|
22
22
|
*/
|
|
23
23
|
readonly onRequest?: (record: ProxyRequestRecord) => void;
|
|
24
|
+
/**
|
|
25
|
+
* The headers whose values its records show as sent, in requests and responses, besides `DEFAULT_RECORD_HEADERS`
|
|
26
|
+
* (such as `content-type`), which it adds to: such as `["dpop"]`; names are compared without regard to case. Every
|
|
27
|
+
* other header's value reads `<redacted>` (`REDACTED_HEADER`),
|
|
28
|
+
* but `authorization` and `proxy-authorization`, which show their scheme, and `cookie` and `set-cookie`, which show
|
|
29
|
+
* each cookie's name; those four can't be listed. A record always holds each header's name. By default none beyond the defaults.
|
|
30
|
+
*/
|
|
31
|
+
readonly recordHeaders?: readonly string[];
|
|
24
32
|
}
|
|
25
33
|
/** A running proxy: a local server that adds a container's test id for clients that can't. */
|
|
26
34
|
export interface ContainerProxy {
|
|
@@ -86,7 +94,8 @@ export interface ContainerProxy {
|
|
|
86
94
|
* Starts a proxy that forwards each request to the container's Testserver URL with its test id added, unless a
|
|
87
95
|
* fault rule (`proxy.fault`) changes what the client gets for it. Method, path, query, headers and body pass
|
|
88
96
|
* through, `host` becomes Testserver's, and bodies stream both ways undecoded, while the proxy keeps a decoded,
|
|
89
|
-
* redacted copy of each for its record. A request Testserver can't be reached for gets a 502.
|
|
97
|
+
* redacted copy of each for its record. A request Testserver can't be reached for gets a 502. Throws a `TypeError`
|
|
98
|
+
* for a bad `recordHeaders`, before it listens.
|
|
90
99
|
*/
|
|
91
100
|
export declare function startProxy(options: ProxyOptions): Promise<ContainerProxy>;
|
|
92
101
|
/** Starts a proxy, runs `body` with it, and closes it however `body` finishes. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Agent, createServer, request as httpRequest, } from "node:http";
|
|
2
2
|
import { Agent as HttpsAgent, request as httpsRequest } from "node:https";
|
|
3
|
-
import { splitTarget } from "../records/index.js";
|
|
3
|
+
import { checkRecordHeaders, splitTarget } from "../records/index.js";
|
|
4
4
|
import { systemClock, TEST_ID_HEADER } from "../testserver/index.js";
|
|
5
5
|
import { Exchange, passThrough } from "./exchange.js";
|
|
6
6
|
import { applyFault } from "./faulted-exchange.js";
|
|
@@ -10,9 +10,11 @@ import { upstreamHeaders } from "./records.js";
|
|
|
10
10
|
* Starts a proxy that forwards each request to the container's Testserver URL with its test id added, unless a
|
|
11
11
|
* fault rule (`proxy.fault`) changes what the client gets for it. Method, path, query, headers and body pass
|
|
12
12
|
* through, `host` becomes Testserver's, and bodies stream both ways undecoded, while the proxy keeps a decoded,
|
|
13
|
-
* redacted copy of each for its record. A request Testserver can't be reached for gets a 502.
|
|
13
|
+
* redacted copy of each for its record. A request Testserver can't be reached for gets a 502. Throws a `TypeError`
|
|
14
|
+
* for a bad `recordHeaders`, before it listens.
|
|
14
15
|
*/
|
|
15
16
|
export async function startProxy(options) {
|
|
17
|
+
const recordHeaders = checkRecordHeaders(options.recordHeaders);
|
|
16
18
|
const upstream = new URL(options.container.testserverUrl);
|
|
17
19
|
const secure = upstream.protocol === "https:";
|
|
18
20
|
if (!secure && upstream.protocol !== "http:") {
|
|
@@ -37,7 +39,7 @@ export async function startProxy(options) {
|
|
|
37
39
|
}),
|
|
38
40
|
agent,
|
|
39
41
|
}, onAnswer);
|
|
40
|
-
const deps = { now: () => systemClock.now(), send, onRequest: options.onRequest };
|
|
42
|
+
const deps = { now: () => systemClock.now(), send, onRequest: options.onRequest, recordHeaders };
|
|
41
43
|
const server = createServer((request, response) => {
|
|
42
44
|
// Matched once, as the headers arrive: a rule added later never applies to this request.
|
|
43
45
|
const rule = faults.take(request.method ?? "GET", splitTarget(request.url ?? "/").path);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
-
import { type RecordedBody, type RequestOutcome, type RequestRecordFields } from "../records/index.ts";
|
|
2
|
+
import { type RecordedBody, type RecordedHeaders, type RequestOutcome, type RequestRecordFields } from "../records/index.ts";
|
|
3
3
|
import type { ProxyFault } from "./faults.ts";
|
|
4
|
-
/** The header the `vercel` CLI sends with the same id on every request of one invocation. */
|
|
5
|
-
export declare const SESSION_ID_HEADER = "x-vercel-cli-session-id";
|
|
6
4
|
/**
|
|
7
5
|
* The outcome of a proxy record whose exchange was still open when `proxy.requests` was read: no `status` or
|
|
8
|
-
* `error`, no `responseBody`, and a `durationMs` that runs to the read.
|
|
6
|
+
* `error`, no `responseHeaders` or `responseBody`, and a `durationMs` that runs to the read.
|
|
9
7
|
*/
|
|
10
8
|
export type OpenRequestOutcome = {
|
|
11
9
|
readonly open: true;
|
|
10
|
+
readonly responseHeaders?: never;
|
|
11
|
+
readonly responseBody?: never;
|
|
12
12
|
};
|
|
13
13
|
/** How a proxied exchange stands: ended as `RequestOutcome` says, or still open. */
|
|
14
14
|
export type ProxyRequestOutcome = RequestOutcome | OpenRequestOutcome;
|
|
@@ -18,13 +18,12 @@ export type ProxyRequestOutcome = RequestOutcome | OpenRequestOutcome;
|
|
|
18
18
|
* as the client sent it, `startedAt` is the proxy clock's reading at its arrival, `durationMs` runs from its arrival
|
|
19
19
|
* to the exchange's end (or, for an open record, to the read), a fault rule's delay included, and `error` without a
|
|
20
20
|
* `status` means no answer reached the client. An `error` beside a `status` says the answer broke off, or, with a
|
|
21
|
-
* `failure`, that it was Testserver's 503 for a stopped container (`answeredOutcome`).
|
|
22
|
-
*
|
|
21
|
+
* `failure`, that it was Testserver's 503 for a stopped container (`answeredOutcome`). `requestHeaders` are the
|
|
22
|
+
* client's as it sent them, before the proxy sets `host` and adds the test id; `responseHeaders` are those the client
|
|
23
|
+
* got with the answer, Testserver's or a fault rule's, less the hop-by-hop headers the proxy never forwards. No token
|
|
24
|
+
* reaches a record (`records/body.ts`, `records/headers.ts`).
|
|
23
25
|
*/
|
|
24
26
|
export type ProxyRequestRecord = RequestRecordFields & {
|
|
25
|
-
readonly userAgent?: string;
|
|
26
|
-
/** The `vercel` CLI's `x-vercel-cli-session-id`, the same for every request of one invocation. */
|
|
27
|
-
readonly sessionId?: string;
|
|
28
27
|
/**
|
|
29
28
|
* The fault rule the request matched, if any: its action, and what Testserver answered when the proxy forwarded
|
|
30
29
|
* it. Then `status`, `error` and `responseBody` say what the client got.
|
|
@@ -33,25 +32,26 @@ export type ProxyRequestRecord = RequestRecordFields & {
|
|
|
33
32
|
} & ProxyRequestOutcome;
|
|
34
33
|
/** Whether `record`'s exchange was still open when it was read. */
|
|
35
34
|
export declare function isOpenRecord(record: ProxyRequestRecord): record is ProxyRequestRecord & OpenRequestOutcome;
|
|
36
|
-
/** The record of a request with `method`, `target` and `
|
|
35
|
+
/** The record of a request with `method`, `target` and `requestHeaders` whose exchange stands as `outcome`. */
|
|
37
36
|
export declare function proxyRecord(request: {
|
|
38
37
|
readonly method: string;
|
|
39
38
|
readonly target: string;
|
|
40
|
-
readonly
|
|
39
|
+
readonly requestHeaders: RecordedHeaders;
|
|
41
40
|
readonly startedAt: number;
|
|
42
41
|
readonly durationMs: number;
|
|
43
42
|
readonly outcome: ProxyRequestOutcome;
|
|
44
43
|
readonly requestBody?: RecordedBody | undefined;
|
|
45
|
-
readonly responseBody?: RecordedBody | undefined;
|
|
46
44
|
readonly fault?: ProxyFault | undefined;
|
|
47
45
|
}): ProxyRequestRecord;
|
|
48
46
|
/**
|
|
49
|
-
* How an exchange whose answer from Testserver, with `status` and `responseBody`, arrived whole
|
|
50
|
-
* alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
|
|
51
|
-
* that failure's description as `error`, since the container the request was for had
|
|
52
|
-
* evicted it.
|
|
47
|
+
* How an exchange whose answer from Testserver, with `status`, `responseHeaders` and `responseBody`, arrived whole
|
|
48
|
+
* ended: with that answer alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
|
|
49
|
+
* `container-stopped` failure and that failure's description as `error`, since the container the request was for had
|
|
50
|
+
* stopped, as when Testserver evicted it.
|
|
53
51
|
*/
|
|
54
|
-
export declare function answeredOutcome(status: number, responseBody: RecordedBody | undefined): RequestOutcome;
|
|
52
|
+
export declare function answeredOutcome(status: number, responseHeaders: RecordedHeaders, responseBody: RecordedBody | undefined): RequestOutcome;
|
|
53
|
+
/** Node's `rawHeaders`, a flat list of names and values, as name and value pairs. */
|
|
54
|
+
export declare function rawHeaderPairs(raw: readonly string[]): [string, string][];
|
|
55
55
|
/**
|
|
56
56
|
* The headers to send upstream: the client's, less hop-by-hop headers, with `host` set to Testserver's and the
|
|
57
57
|
* test id header set to `testId`, replacing any the client sent.
|