@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,24 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { splitTarget, } from "../records/index.js";
|
|
2
2
|
import { BODY_EXCERPT_CHARS, describeFailure, httpFailure } from "../testserver/index.js";
|
|
3
|
-
/** The header the `vercel` CLI sends with the same id on every request of one invocation. */
|
|
4
|
-
export const SESSION_ID_HEADER = "x-vercel-cli-session-id";
|
|
5
3
|
/** Whether `record`'s exchange was still open when it was read. */
|
|
6
4
|
export function isOpenRecord(record) {
|
|
7
5
|
return "open" in record;
|
|
8
6
|
}
|
|
9
|
-
/** The record of a request with `method`, `target` and `
|
|
7
|
+
/** The record of a request with `method`, `target` and `requestHeaders` whose exchange stands as `outcome`. */
|
|
10
8
|
export function proxyRecord(request) {
|
|
11
|
-
const userAgent = headerText(request.headers["user-agent"]);
|
|
12
|
-
const sessionId = headerText(request.headers[SESSION_ID_HEADER]);
|
|
13
9
|
return {
|
|
14
10
|
method: request.method,
|
|
15
11
|
url: request.target,
|
|
16
12
|
...splitTarget(request.target),
|
|
17
|
-
|
|
18
|
-
...(userAgent === undefined ? {} : { userAgent }),
|
|
19
|
-
...(sessionId === undefined ? {} : { sessionId }),
|
|
13
|
+
requestHeaders: request.requestHeaders,
|
|
20
14
|
...(request.requestBody === undefined ? {} : { requestBody: request.requestBody }),
|
|
21
|
-
...(request.responseBody === undefined ? {} : { responseBody: request.responseBody }),
|
|
22
15
|
...(request.fault === undefined ? {} : { fault: request.fault }),
|
|
23
16
|
startedAt: request.startedAt,
|
|
24
17
|
durationMs: request.durationMs,
|
|
@@ -26,16 +19,17 @@ export function proxyRecord(request) {
|
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
21
|
/**
|
|
29
|
-
* How an exchange whose answer from Testserver, with `status` and `responseBody`, arrived whole
|
|
30
|
-
* alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
|
|
31
|
-
* that failure's description as `error`, since the container the request was for had
|
|
32
|
-
* evicted it.
|
|
22
|
+
* How an exchange whose answer from Testserver, with `status`, `responseHeaders` and `responseBody`, arrived whole
|
|
23
|
+
* ended: with that answer alone, or, for Testserver's 503 for a stopped container (`httpFailure`), with its
|
|
24
|
+
* `container-stopped` failure and that failure's description as `error`, since the container the request was for had
|
|
25
|
+
* stopped, as when Testserver evicted it.
|
|
33
26
|
*/
|
|
34
|
-
export function answeredOutcome(status, responseBody) {
|
|
27
|
+
export function answeredOutcome(status, responseHeaders, responseBody) {
|
|
28
|
+
const answer = { status, responseHeaders, ...(responseBody === undefined ? {} : { responseBody }) };
|
|
35
29
|
if (status !== 503 || responseBody?.kind !== "text")
|
|
36
|
-
return
|
|
30
|
+
return answer;
|
|
37
31
|
const failure = httpFailure(status, responseBody.text.slice(0, BODY_EXCERPT_CHARS));
|
|
38
|
-
return failure.kind === "container-stopped" ? {
|
|
32
|
+
return failure.kind === "container-stopped" ? { ...answer, error: describeFailure(failure), failure } : answer;
|
|
39
33
|
}
|
|
40
34
|
/** Headers that describe one connection, not the message, so the proxy never forwards them. */
|
|
41
35
|
const HOP_BY_HOP = new Set([
|
|
@@ -48,6 +42,13 @@ const HOP_BY_HOP = new Set([
|
|
|
48
42
|
"trailer",
|
|
49
43
|
"upgrade",
|
|
50
44
|
]);
|
|
45
|
+
/** Node's `rawHeaders`, a flat list of names and values, as name and value pairs. */
|
|
46
|
+
export function rawHeaderPairs(raw) {
|
|
47
|
+
const pairs = [];
|
|
48
|
+
for (let at = 0; at + 1 < raw.length; at += 2)
|
|
49
|
+
pairs.push([raw[at] ?? "", raw[at + 1] ?? ""]);
|
|
50
|
+
return pairs;
|
|
51
|
+
}
|
|
51
52
|
/**
|
|
52
53
|
* The headers to send upstream: the client's, less hop-by-hop headers, with `host` set to Testserver's and the
|
|
53
54
|
* test id header set to `testId`, replacing any the client sent.
|
|
@@ -39,28 +39,28 @@ export declare class BodyCapture {
|
|
|
39
39
|
#private;
|
|
40
40
|
push(chunk: Uint8Array): void;
|
|
41
41
|
/** The whole body, decoded by `headers`; `undefined` when it was empty. */
|
|
42
|
-
complete(headers: IncomingHttpHeaders,
|
|
42
|
+
complete(headers: IncomingHttpHeaders, credentials: string | undefined): RecordedBody | undefined;
|
|
43
43
|
/** A body that broke off partway; `undefined` when none of it arrived. */
|
|
44
44
|
incomplete(headers: IncomingHttpHeaders): RecordedBody | undefined;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the
|
|
48
|
-
*
|
|
47
|
+
* A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the credentials of
|
|
48
|
+
* the request's own `authorization` header. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
|
|
49
49
|
* `RECORDED_BODY_CAP_BYTES`, when it is ignored. `undefined` for an empty body. The proxy's `BodyCapture` and an API
|
|
50
50
|
* request's whole body both come through here.
|
|
51
51
|
*/
|
|
52
|
-
export declare function recordedBody(kept: Uint8Array, bytes: number, headers: IncomingHttpHeaders,
|
|
52
|
+
export declare function recordedBody(kept: Uint8Array, bytes: number, headers: IncomingHttpHeaders, credentials: string | undefined): RecordedBody | undefined;
|
|
53
53
|
/**
|
|
54
54
|
* The record of a body of `bytes` bytes sent with `headers`. `raw` is the body as sent, or `undefined` when it was
|
|
55
55
|
* over the cap. Decompresses gzip, deflate and br, then decodes by `content-type`.
|
|
56
56
|
*/
|
|
57
57
|
export declare function decodeBody(raw: Uint8Array | undefined, bytes: number, headers: IncomingHttpHeaders): RecordedBody;
|
|
58
58
|
/**
|
|
59
|
-
* `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `
|
|
60
|
-
* request's own
|
|
59
|
+
* `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `credentials`,
|
|
60
|
+
* those of the request's own `authorization` header, whatever its scheme, replaced wherever they appear. An object under a token field is redacted like any
|
|
61
61
|
* other. Expects a body from `decodeBody`, whose JSON nesting is bounded; `recordedBody` composes the two.
|
|
62
62
|
*/
|
|
63
|
-
export declare function redactBody(body: RecordedBody,
|
|
63
|
+
export declare function redactBody(body: RecordedBody, credentials: string | undefined): RecordedBody;
|
|
64
64
|
/**
|
|
65
65
|
* `value` with every token field's string value, directly or inside arrays, replaced by `<token>`, as a JSON body's
|
|
66
66
|
* are in a record. An object under a token field is redacted like any other. For printing a value no record holds,
|
|
@@ -77,8 +77,6 @@ export declare function tokenSecrets(value: unknown): Set<string>;
|
|
|
77
77
|
* another is replaced whole. An empty secret is skipped. A container's `redact` and the Vercel CLI invoker's use it.
|
|
78
78
|
*/
|
|
79
79
|
export declare function redactSecrets(text: string, secrets: Iterable<string>): string;
|
|
80
|
-
/** The bearer token in an `authorization` header, such as `Bearer abc`, or `undefined`. */
|
|
81
|
-
export declare function bearerToken(authorization: string | undefined): string | undefined;
|
|
82
80
|
/**
|
|
83
81
|
* Parsed search params; a key given more than once maps to every value, in order. Collects into a `Map` so a key
|
|
84
82
|
* such as `__proto__` becomes a plain own property.
|
|
@@ -35,8 +35,8 @@ export class BodyCapture {
|
|
|
35
35
|
this.#chunks.push(chunk);
|
|
36
36
|
}
|
|
37
37
|
/** The whole body, decoded by `headers`; `undefined` when it was empty. */
|
|
38
|
-
complete(headers,
|
|
39
|
-
return recordedBody(Buffer.concat(this.#chunks), this.#bytes, headers,
|
|
38
|
+
complete(headers, credentials) {
|
|
39
|
+
return recordedBody(Buffer.concat(this.#chunks), this.#bytes, headers, credentials);
|
|
40
40
|
}
|
|
41
41
|
/** A body that broke off partway; `undefined` when none of it arrived. */
|
|
42
42
|
incomplete(headers) {
|
|
@@ -46,16 +46,16 @@ export class BodyCapture {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the
|
|
50
|
-
*
|
|
49
|
+
* A request or response body as a record keeps it: decoded by `headers`, capped, and redacted with the credentials of
|
|
50
|
+
* the request's own `authorization` header. The body was `bytes` bytes long, and `kept` holds all of it unless it was over
|
|
51
51
|
* `RECORDED_BODY_CAP_BYTES`, when it is ignored. `undefined` for an empty body. The proxy's `BodyCapture` and an API
|
|
52
52
|
* request's whole body both come through here.
|
|
53
53
|
*/
|
|
54
|
-
export function recordedBody(kept, bytes, headers,
|
|
54
|
+
export function recordedBody(kept, bytes, headers, credentials) {
|
|
55
55
|
if (bytes === 0)
|
|
56
56
|
return undefined;
|
|
57
57
|
const raw = bytes > RECORDED_BODY_CAP_BYTES ? undefined : kept;
|
|
58
|
-
return redactBody(decodeBody(raw, bytes, headers),
|
|
58
|
+
return redactBody(decodeBody(raw, bytes, headers), credentials);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* The record of a body of `bytes` bytes sent with `headers`. `raw` is the body as sent, or `undefined` when it was
|
|
@@ -92,12 +92,12 @@ export function decodeBody(raw, bytes, headers) {
|
|
|
92
92
|
return omitted("binary", bytes, headers);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `
|
|
96
|
-
* request's own
|
|
95
|
+
* `body` with every token field's string value, directly or inside arrays, replaced by `<token>`, and `credentials`,
|
|
96
|
+
* those of the request's own `authorization` header, whatever its scheme, replaced wherever they appear. An object under a token field is redacted like any
|
|
97
97
|
* other. Expects a body from `decodeBody`, whose JSON nesting is bounded; `recordedBody` composes the two.
|
|
98
98
|
*/
|
|
99
|
-
export function redactBody(body,
|
|
100
|
-
const scrub = (text) => (
|
|
99
|
+
export function redactBody(body, credentials) {
|
|
100
|
+
const scrub = (text) => (credentials === undefined ? text : redactSecrets(text, [credentials]));
|
|
101
101
|
switch (body.kind) {
|
|
102
102
|
case "json":
|
|
103
103
|
return { kind: "json", value: redactValue(body.value, scrub) };
|
|
@@ -183,11 +183,6 @@ function redactFields(fields, scrub) {
|
|
|
183
183
|
}
|
|
184
184
|
return Object.fromEntries(redacted);
|
|
185
185
|
}
|
|
186
|
-
/** The bearer token in an `authorization` header, such as `Bearer abc`, or `undefined`. */
|
|
187
|
-
export function bearerToken(authorization) {
|
|
188
|
-
const match = /^\s*bearer\s+(\S+)\s*$/i.exec(authorization ?? "");
|
|
189
|
-
return match?.[1];
|
|
190
|
-
}
|
|
191
186
|
/**
|
|
192
187
|
* Parsed search params; a key given more than once maps to every value, in order. Collects into a `Map` so a key
|
|
193
188
|
* such as `__proto__` becomes a plain own property.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** An `authorization` header's value, split into its scheme and its credentials. */
|
|
2
|
+
export interface Authorization {
|
|
3
|
+
/** The scheme as sent, such as `Bearer` or `DPoP`; absent for a value that is one word. */
|
|
4
|
+
readonly scheme?: string;
|
|
5
|
+
/** Everything after the scheme, trimmed: the secret a record must not hold. */
|
|
6
|
+
readonly credentials: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* An `authorization` header's value read as any scheme and its credentials: `DPoP abc` is the scheme `DPoP` and
|
|
10
|
+
* the credentials `abc`. A value with no scheme, one word such as `abc`, is all credentials. `undefined` for an
|
|
11
|
+
* absent or blank value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseAuthorization(value: string | undefined): Authorization | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The fewest characters a request's `authorization` credentials must have for a record to search for them and
|
|
16
|
+
* replace them in its bodies and shown headers, and for a container to learn them. A shorter value, such as `a`,
|
|
17
|
+
* would replace every `a` in the record, and no real token is that short. The `authorization` header itself always
|
|
18
|
+
* hides its credentials, whatever their length.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MIN_CREDENTIAL_CHARS = 8;
|
|
21
|
+
/**
|
|
22
|
+
* The secret a record replaces wherever it appears: the credentials of an `authorization` header's value, whatever
|
|
23
|
+
* its scheme, or `undefined` when there are none or they are shorter than `MIN_CREDENTIAL_CHARS`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function authorizationSecret(value: string | undefined): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* What a record holds in place of the value of a header no rule shows, `DEFAULT_RECORD_HEADERS` doesn't hold, and no
|
|
28
|
+
* `recordHeaders` list names.
|
|
29
|
+
*/
|
|
30
|
+
export declare const REDACTED_HEADER = "<redacted>";
|
|
31
|
+
/**
|
|
32
|
+
* A request's or an answer's headers as a record keeps them (`recordedHeaders`): names lowercased, in the order each
|
|
33
|
+
* name first came, each value hidden unless a rule, `DEFAULT_RECORD_HEADERS` or the record's `recordHeaders` list
|
|
34
|
+
* shows it. A shown header sent
|
|
35
|
+
* more than once is one string: its values joined with `, `, as HTTP combines a repeated field, but `cookie`, joined
|
|
36
|
+
* with `; ` as a client sends its cookies, and `set-cookie`, joined with a line feed, since a cookie's own value or
|
|
37
|
+
* attributes can hold `, ` but no header value holds a line break. Split `set-cookie` on `\n` to read each cookie. A
|
|
38
|
+
* hidden header reads `<redacted>` once, however many times it was sent.
|
|
39
|
+
*/
|
|
40
|
+
export type RecordedHeaders = Readonly<Record<string, string>>;
|
|
41
|
+
/** Headers as `recordedHeaders` takes them: name and value pairs, a value given as a list once per value. */
|
|
42
|
+
export type HeaderEntries = Iterable<readonly [string, string | readonly string[] | undefined]>;
|
|
43
|
+
/** How `recordedHeaders` redacts: the request's own secret, and the headers whose values are shown as sent. */
|
|
44
|
+
export interface HeaderRedaction {
|
|
45
|
+
/** The request's `authorization` credentials (`authorizationSecret`), replaced in every shown value. */
|
|
46
|
+
readonly secret: string | undefined;
|
|
47
|
+
/** The lowercased names whose values are shown as sent (`checkRecordHeaders`). */
|
|
48
|
+
readonly shown: ReadonlySet<string>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The headers every record shows as sent, whatever its `recordHeaders` list: standard HTTP headers that describe the
|
|
52
|
+
* message or the connection, never the user or a resource, and whose values never hold a credential or a code.
|
|
53
|
+
* `location` is not one, since a redirect can carry a code or a token in its query, nor is any header of one
|
|
54
|
+
* product or protocol, such as `www-authenticate` or `dpop`: a consumer lists those itself.
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_RECORD_HEADERS: readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
* `names`, a `recordHeaders` option, as the set `recordedHeaders` shows: `DEFAULT_RECORD_HEADERS` and each of
|
|
59
|
+
* `names`, lowercased. A list adds to the defaults; nothing turns them off. Throws a `TypeError`
|
|
60
|
+
* for a list that isn't an array, a name that isn't a valid header name, and `authorization`, `proxy-authorization`,
|
|
61
|
+
* `cookie` or `set-cookie`, whose values a record never shows whole.
|
|
62
|
+
*/
|
|
63
|
+
export declare function checkRecordHeaders(names: readonly string[] | undefined): ReadonlySet<string>;
|
|
64
|
+
/**
|
|
65
|
+
* The canonical key of `names`, a `recordHeaders` option: the JSON of the names `checkRecordHeaders` shows, sorted,
|
|
66
|
+
* so two lists that show the same headers give the same key. `undefined`, `[]`, and `["Content-Type"]` do, since a
|
|
67
|
+
* list adds to the defaults, and so do `["X-Trace", "dpop"]` and `["dpop", "x-trace", "DPoP"]`. Throws
|
|
68
|
+
* `checkRecordHeaders`' `TypeError` for a list it refuses.
|
|
69
|
+
*/
|
|
70
|
+
export declare function recordHeadersKey(names: readonly string[] | undefined): string;
|
|
71
|
+
/**
|
|
72
|
+
* `headers` as a record keeps them. Every value is hidden, reading `<redacted>`, unless a rule or `shown` shows it:
|
|
73
|
+
* `authorization` and `proxy-authorization` show their scheme and read `<token>` for the credentials, such as
|
|
74
|
+
* `DPoP <token>`, and a value with no scheme reads `<token>`; `cookie` and `set-cookie` show each cookie's name, and
|
|
75
|
+
* `set-cookie` its attributes, and read `<token>` for each value; and a header `shown` names is kept as sent, with
|
|
76
|
+
* `secret`, the request's own `authorization` credentials, replaced by `<token>` wherever it appears. A header's name
|
|
77
|
+
* is always recorded, so a test can tell it was sent.
|
|
78
|
+
*/
|
|
79
|
+
export declare function recordedHeaders(headers: HeaderEntries, redaction: HeaderRedaction): RecordedHeaders;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { validateHeaderName } from "node:http";
|
|
2
|
+
import { REDACTED, redactSecrets } from "./body.js";
|
|
3
|
+
/** An auth scheme is an HTTP token (RFC 9110, section 11.1). */
|
|
4
|
+
const SCHEME_AND_CREDENTIALS = /^([!#$%&'*+.^_`|~0-9A-Za-z-]+)\s+(\S[\s\S]*)$/;
|
|
5
|
+
/**
|
|
6
|
+
* An `authorization` header's value read as any scheme and its credentials: `DPoP abc` is the scheme `DPoP` and
|
|
7
|
+
* the credentials `abc`. A value with no scheme, one word such as `abc`, is all credentials. `undefined` for an
|
|
8
|
+
* absent or blank value.
|
|
9
|
+
*/
|
|
10
|
+
export function parseAuthorization(value) {
|
|
11
|
+
const trimmed = (value ?? "").trim();
|
|
12
|
+
if (trimmed === "")
|
|
13
|
+
return undefined;
|
|
14
|
+
const match = SCHEME_AND_CREDENTIALS.exec(trimmed);
|
|
15
|
+
const scheme = match?.[1];
|
|
16
|
+
const credentials = match?.[2];
|
|
17
|
+
if (scheme === undefined || credentials === undefined)
|
|
18
|
+
return { credentials: trimmed };
|
|
19
|
+
return { scheme, credentials };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The fewest characters a request's `authorization` credentials must have for a record to search for them and
|
|
23
|
+
* replace them in its bodies and shown headers, and for a container to learn them. A shorter value, such as `a`,
|
|
24
|
+
* would replace every `a` in the record, and no real token is that short. The `authorization` header itself always
|
|
25
|
+
* hides its credentials, whatever their length.
|
|
26
|
+
*/
|
|
27
|
+
export const MIN_CREDENTIAL_CHARS = 8;
|
|
28
|
+
/**
|
|
29
|
+
* The secret a record replaces wherever it appears: the credentials of an `authorization` header's value, whatever
|
|
30
|
+
* its scheme, or `undefined` when there are none or they are shorter than `MIN_CREDENTIAL_CHARS`.
|
|
31
|
+
*/
|
|
32
|
+
export function authorizationSecret(value) {
|
|
33
|
+
const credentials = parseAuthorization(value)?.credentials;
|
|
34
|
+
return credentials === undefined || credentials.length < MIN_CREDENTIAL_CHARS ? undefined : credentials;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a record holds in place of the value of a header no rule shows, `DEFAULT_RECORD_HEADERS` doesn't hold, and no
|
|
38
|
+
* `recordHeaders` list names.
|
|
39
|
+
*/
|
|
40
|
+
export const REDACTED_HEADER = "<redacted>";
|
|
41
|
+
/**
|
|
42
|
+
* The headers every record shows as sent, whatever its `recordHeaders` list: standard HTTP headers that describe the
|
|
43
|
+
* message or the connection, never the user or a resource, and whose values never hold a credential or a code.
|
|
44
|
+
* `location` is not one, since a redirect can carry a code or a token in its query, nor is any header of one
|
|
45
|
+
* product or protocol, such as `www-authenticate` or `dpop`: a consumer lists those itself.
|
|
46
|
+
*/
|
|
47
|
+
export const DEFAULT_RECORD_HEADERS = [
|
|
48
|
+
"content-type",
|
|
49
|
+
"content-length",
|
|
50
|
+
"content-encoding",
|
|
51
|
+
"transfer-encoding",
|
|
52
|
+
"accept",
|
|
53
|
+
"accept-encoding",
|
|
54
|
+
"user-agent",
|
|
55
|
+
"date",
|
|
56
|
+
"cache-control",
|
|
57
|
+
"retry-after",
|
|
58
|
+
];
|
|
59
|
+
/** Headers whose credentials are always hidden, their scheme shown. */
|
|
60
|
+
const AUTHORIZATION_HEADERS = new Set(["authorization", "proxy-authorization"]);
|
|
61
|
+
/** Headers whose cookie values are always hidden, their names (and `set-cookie`'s attributes) shown. */
|
|
62
|
+
const COOKIE_HEADERS = new Set(["cookie", "set-cookie"]);
|
|
63
|
+
/**
|
|
64
|
+
* `names`, a `recordHeaders` option, as the set `recordedHeaders` shows: `DEFAULT_RECORD_HEADERS` and each of
|
|
65
|
+
* `names`, lowercased. A list adds to the defaults; nothing turns them off. Throws a `TypeError`
|
|
66
|
+
* for a list that isn't an array, a name that isn't a valid header name, and `authorization`, `proxy-authorization`,
|
|
67
|
+
* `cookie` or `set-cookie`, whose values a record never shows whole.
|
|
68
|
+
*/
|
|
69
|
+
export function checkRecordHeaders(names) {
|
|
70
|
+
const shown = new Set(DEFAULT_RECORD_HEADERS);
|
|
71
|
+
if (names === undefined)
|
|
72
|
+
return shown;
|
|
73
|
+
if (!Array.isArray(names))
|
|
74
|
+
throw new TypeError("recordHeaders must be an array of header names");
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
if (typeof name !== "string")
|
|
77
|
+
throw new TypeError(`recordHeaders holds ${String(name)}, not a header name`);
|
|
78
|
+
try {
|
|
79
|
+
validateHeaderName(name);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new TypeError(`recordHeaders holds ${JSON.stringify(name)}, not a valid header name`);
|
|
83
|
+
}
|
|
84
|
+
const key = name.toLowerCase();
|
|
85
|
+
if (AUTHORIZATION_HEADERS.has(key) || COOKIE_HEADERS.has(key)) {
|
|
86
|
+
throw new TypeError(`recordHeaders can't name ${key}: a record always shows only its ${AUTHORIZATION_HEADERS.has(key) ? "scheme" : "cookie names"}`);
|
|
87
|
+
}
|
|
88
|
+
shown.add(key);
|
|
89
|
+
}
|
|
90
|
+
return shown;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The canonical key of `names`, a `recordHeaders` option: the JSON of the names `checkRecordHeaders` shows, sorted,
|
|
94
|
+
* so two lists that show the same headers give the same key. `undefined`, `[]`, and `["Content-Type"]` do, since a
|
|
95
|
+
* list adds to the defaults, and so do `["X-Trace", "dpop"]` and `["dpop", "x-trace", "DPoP"]`. Throws
|
|
96
|
+
* `checkRecordHeaders`' `TypeError` for a list it refuses.
|
|
97
|
+
*/
|
|
98
|
+
export function recordHeadersKey(names) {
|
|
99
|
+
return JSON.stringify([...checkRecordHeaders(names)].toSorted());
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `headers` as a record keeps them. Every value is hidden, reading `<redacted>`, unless a rule or `shown` shows it:
|
|
103
|
+
* `authorization` and `proxy-authorization` show their scheme and read `<token>` for the credentials, such as
|
|
104
|
+
* `DPoP <token>`, and a value with no scheme reads `<token>`; `cookie` and `set-cookie` show each cookie's name, and
|
|
105
|
+
* `set-cookie` its attributes, and read `<token>` for each value; and a header `shown` names is kept as sent, with
|
|
106
|
+
* `secret`, the request's own `authorization` credentials, replaced by `<token>` wherever it appears. A header's name
|
|
107
|
+
* is always recorded, so a test can tell it was sent.
|
|
108
|
+
*/
|
|
109
|
+
export function recordedHeaders(headers, redaction) {
|
|
110
|
+
const collected = new Map();
|
|
111
|
+
for (const [name, value] of headers) {
|
|
112
|
+
if (value === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
const key = name.toLowerCase();
|
|
115
|
+
const values = collected.get(key) ?? [];
|
|
116
|
+
values.push(...(typeof value === "string" ? [value] : value));
|
|
117
|
+
collected.set(key, values);
|
|
118
|
+
}
|
|
119
|
+
// Collected in a `Map`, so a header named such as `__proto__` becomes a plain own property.
|
|
120
|
+
return Object.fromEntries([...collected].map(([name, values]) => [name, recordedValue(name, values, redaction)]));
|
|
121
|
+
}
|
|
122
|
+
/** Every value of the header `name` as one string, shown or hidden by its rule. */
|
|
123
|
+
function recordedValue(name, values, redaction) {
|
|
124
|
+
if (AUTHORIZATION_HEADERS.has(name))
|
|
125
|
+
return values.map(redactAuthorization).join(", ");
|
|
126
|
+
if (name === "cookie")
|
|
127
|
+
return values.map(redactRequestCookies).join("; ");
|
|
128
|
+
if (name === "set-cookie")
|
|
129
|
+
return values.map(redactSetCookie).join("\n");
|
|
130
|
+
if (!redaction.shown.has(name))
|
|
131
|
+
return REDACTED_HEADER;
|
|
132
|
+
const { secret } = redaction;
|
|
133
|
+
return values.map((value) => (secret === undefined ? value : redactSecrets(value, [secret]))).join(", ");
|
|
134
|
+
}
|
|
135
|
+
/** An `authorization` value as its scheme and `<token>`, or `<token>` alone for a value with no scheme. */
|
|
136
|
+
function redactAuthorization(value) {
|
|
137
|
+
const parsed = parseAuthorization(value);
|
|
138
|
+
if (parsed === undefined)
|
|
139
|
+
return value;
|
|
140
|
+
return parsed.scheme === undefined ? REDACTED : `${parsed.scheme} ${REDACTED}`;
|
|
141
|
+
}
|
|
142
|
+
/** A `cookie` value with each cookie's value reading `<token>`. */
|
|
143
|
+
function redactRequestCookies(value) {
|
|
144
|
+
return parts(value).map(redactCookie).join("; ");
|
|
145
|
+
}
|
|
146
|
+
/** A `set-cookie` value with its cookie's value reading `<token>`, its attributes kept. */
|
|
147
|
+
function redactSetCookie(value) {
|
|
148
|
+
const [cookie, ...attributes] = value.split(";").map((each) => each.trim());
|
|
149
|
+
return [redactCookie(cookie ?? ""), ...attributes.filter((each) => each !== "")].join("; ");
|
|
150
|
+
}
|
|
151
|
+
/** The non-empty `;`-separated parts of `value`, trimmed. */
|
|
152
|
+
function parts(value) {
|
|
153
|
+
return value
|
|
154
|
+
.split(";")
|
|
155
|
+
.map((each) => each.trim())
|
|
156
|
+
.filter((each) => each !== "");
|
|
157
|
+
}
|
|
158
|
+
/** A `name=value` cookie as `name=<token>`; a cookie with no `=` reads `<token>`. */
|
|
159
|
+
function redactCookie(cookie) {
|
|
160
|
+
const equals = cookie.indexOf("=");
|
|
161
|
+
return equals === -1 ? REDACTED : `${cookie.slice(0, equals).trim()}=${REDACTED}`;
|
|
162
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, type RecordedBody, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.ts";
|
|
2
|
+
export { type Authorization, authorizationSecret, checkRecordHeaders, DEFAULT_RECORD_HEADERS, type HeaderEntries, type HeaderRedaction, MIN_CREDENTIAL_CHARS, parseAuthorization, REDACTED_HEADER, type RecordedHeaders, recordedHeaders, recordHeadersKey, } from "./headers.ts";
|
|
2
3
|
export { type ApiRequestRecord, type ExternalCallRecord, incomingHeaders, type RequestOutcome, type RequestRecordFields, splitTarget, } from "./records.ts";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// The SDK's `records` module: how request records are kept, shared by the proxy's records and a container's API
|
|
2
|
-
// requests. Bodies are decoded, capped and redacted here, and the fields every record holds are defined
|
|
3
|
-
|
|
2
|
+
// requests. Bodies and headers are decoded, capped and redacted here, and the fields every record holds are defined
|
|
3
|
+
// here.
|
|
4
|
+
export { BodyCapture, decodeBody, headerText, parseParams, RECORDED_BODY_CAP_BYTES, recordedBody, REDACTED, redactBody, redactSecrets, redactTokenFields, tokenSecrets, } from "./body.js";
|
|
5
|
+
export { authorizationSecret, checkRecordHeaders, DEFAULT_RECORD_HEADERS, MIN_CREDENTIAL_CHARS, parseAuthorization, REDACTED_HEADER, recordedHeaders, recordHeadersKey, } from "./headers.js";
|
|
4
6
|
export { incomingHeaders, splitTarget, } from "./records.js";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { IncomingHttpHeaders } from "node:http";
|
|
2
2
|
import type { TestserverFailure } from "../testserver/index.ts";
|
|
3
3
|
import { type RecordedBody } from "./body.ts";
|
|
4
|
+
import type { RecordedHeaders } from "./headers.ts";
|
|
4
5
|
/**
|
|
5
|
-
* The fields every request record holds, the proxy's and an API request's, besides how it ended:
|
|
6
|
-
*
|
|
6
|
+
* The fields every request record holds, the proxy's and an API request's, besides how it ended (`RequestOutcome`):
|
|
7
|
+
* what was sent, and when. No token reaches a record (`body.ts`, `headers.ts`).
|
|
7
8
|
*/
|
|
8
9
|
export type RequestRecordFields = {
|
|
9
10
|
readonly method: string;
|
|
@@ -12,12 +13,13 @@ export type RequestRecordFields = {
|
|
|
12
13
|
readonly path: string;
|
|
13
14
|
/** The query, parsed; a key given more than once maps to every value, in order. */
|
|
14
15
|
readonly query: Readonly<Record<string, string | readonly string[]>>;
|
|
15
|
-
/**
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The request's headers as the caller sent them, redacted (`RecordedHeaders`): an `authorization` header reads
|
|
18
|
+
* its scheme and `<token>`, such as `DPoP <token>`. Never a test id header the SDK added.
|
|
19
|
+
*/
|
|
20
|
+
readonly requestHeaders: RecordedHeaders;
|
|
17
21
|
/** Absent for an empty body. */
|
|
18
22
|
readonly requestBody?: RecordedBody;
|
|
19
|
-
/** Absent for an empty body, or when no answer arrived. */
|
|
20
|
-
readonly responseBody?: RecordedBody;
|
|
21
23
|
/**
|
|
22
24
|
* The clock's reading when the request started: for an API request the SDK clock's when `fetch` was called,
|
|
23
25
|
* comparable with a factory call's `startedAt`; for a proxy record the proxy's clock's at its arrival.
|
|
@@ -27,26 +29,33 @@ export type RequestRecordFields = {
|
|
|
27
29
|
readonly durationMs: number;
|
|
28
30
|
};
|
|
29
31
|
/**
|
|
30
|
-
* How a request ended: Testserver's status, with an error if the answer broke off or was
|
|
31
|
-
* arrived. `failure` is the Testserver failure that `error` describes (`describeFailure`), when the SDK read one: beside
|
|
32
|
+
* How a request ended: Testserver's status and what came back with it, with an error if the answer broke off or was
|
|
33
|
+
* refused, or why no answer arrived. `failure` is the Testserver failure that `error` describes (`describeFailure`), when the SDK read one: beside
|
|
32
34
|
* a `status`, it says the status fails the call, as a 410 or Testserver's 503 for a stopped container does, where an
|
|
33
35
|
* `error` without it says the answer broke off; without a `status`, why the call got no answer. An abort, and an
|
|
34
36
|
* error the proxy met on its own connections, have none.
|
|
35
37
|
*/
|
|
36
38
|
export type RequestOutcome = {
|
|
37
39
|
readonly status: number;
|
|
40
|
+
/** The answer's headers, redacted as `requestHeaders` are. */
|
|
41
|
+
readonly responseHeaders: RecordedHeaders;
|
|
42
|
+
/** Absent for an empty body. */
|
|
43
|
+
readonly responseBody?: RecordedBody;
|
|
38
44
|
/** Why the answer broke off after its status arrived, or why its status fails the call. */
|
|
39
45
|
readonly error?: string;
|
|
40
46
|
readonly failure?: TestserverFailure;
|
|
41
47
|
}
|
|
42
|
-
/** No answer arrived. */
|
|
48
|
+
/** No answer arrived, so nothing came back. */
|
|
43
49
|
| {
|
|
44
50
|
readonly error: string;
|
|
45
51
|
readonly failure?: TestserverFailure;
|
|
52
|
+
readonly responseHeaders?: never;
|
|
53
|
+
readonly responseBody?: never;
|
|
46
54
|
};
|
|
47
55
|
/**
|
|
48
56
|
* One API request a container sent with `container.fetch`, recorded once its answer was read or the request
|
|
49
|
-
* failed. It holds a proxy record's fields but `
|
|
57
|
+
* failed. It holds a proxy record's fields but `fault`, and is never open. Its `responseHeaders` are Testserver's,
|
|
58
|
+
* less `content-encoding` and `content-length`, which no longer describe the body `fetch` decompressed.
|
|
50
59
|
*/
|
|
51
60
|
export type ApiRequestRecord = RequestRecordFields & RequestOutcome;
|
|
52
61
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnc-tools/storm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "A test orchestrator: run your tests in the inner loop of development, in the cloud, in a test environment that you define",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vercel-labs/cnc.git",
|
|
@@ -139,11 +139,12 @@
|
|
|
139
139
|
"esbuild": "^0.27.7",
|
|
140
140
|
"typescript": "^7.0.2",
|
|
141
141
|
"typescript-5": "npm:typescript@5.9.3",
|
|
142
|
-
"vitest": "4.1.10"
|
|
142
|
+
"vitest": "4.1.10",
|
|
143
|
+
"vitest-5": "npm:vitest@5.1.0"
|
|
143
144
|
},
|
|
144
145
|
"peerDependencies": {
|
|
145
146
|
"@playwright/test": "^1.56.0",
|
|
146
|
-
"vitest": "^4.1.10"
|
|
147
|
+
"vitest": "^4.1.10 || ^5.0.0"
|
|
147
148
|
},
|
|
148
149
|
"peerDependenciesMeta": {
|
|
149
150
|
"@playwright/test": {
|
package/skills/overview.md
CHANGED
|
@@ -6,7 +6,7 @@ commands: all
|
|
|
6
6
|
|
|
7
7
|
# Overview
|
|
8
8
|
|
|
9
|
-
`storm vitest` runs vitest, in a runner sandbox or on this machine.
|
|
9
|
+
`storm vitest` runs vitest, in a runner sandbox or on this machine. When `storm.config.ts` sets `testPlan: true`, it first counts the test files on this machine, and a resource can size itself from that count. Without it, it counts nothing. `storm playwright` does the same for Playwright. `storm exec` runs a different command, such as `pnpm test`, in the same way, but it does not count tests. After the run, the `runs` commands read the run back on this machine.
|
|
10
10
|
|
|
11
11
|
## Concepts
|
|
12
12
|
|
|
@@ -17,15 +17,15 @@ commands: all
|
|
|
17
17
|
- A **run id** is the name of a run, such as `20261103T192655-8277`. It is the start time of the run in UTC and a short suffix. `storm vitest`, `storm playwright` and `storm exec` print it at the end, in the `logs` line. With `--json`, the result gives it as `runId`.
|
|
18
18
|
- A **run directory** is the directory where a run writes what it did, on the machine that started the run. This is true for a sandboxed run and for an unsandboxed run. Its name is the run id. Do not read its files directly. Use the `runs` commands.
|
|
19
19
|
- A run is **active** while it goes on. A run is **finished** when it has ended and saved its test results. `runs show` shows test results only for a finished run.
|
|
20
|
-
- A **test result** is the final result of one test: `pass`, `fail
|
|
20
|
+
- A **test result** is the final result of one test: `pass`, `fail`, or `skip`, with its errors. The command saves test results only with a storm reporter in the config of its test runner: `stormReporter` for vitest, `@vercel/storm/playwright/reporter` for Playwright. When the command of a run exits 0 but reports no test result, the run warns `no_final_test_results`. The exit code does not change. Do the steps in its `next`: they name the config file and the code to add. Then run the same command again.
|
|
21
21
|
- **Test output** is what one test printed to the console, stdout and stderr together. storm keeps the last 8 MiB of the test output of each test. `droppedChars` counts the characters that storm did not keep.
|
|
22
22
|
- A **runner secret** is a variable in your environment that the `secrets` key of the runner recipe declares, such as an npm token for a private package. A sandboxed run reads it on the machine that starts the run. The run does not start when the variable is not set, is empty, holds a line break or has fewer than 8 characters. A step of the recipe gets the variable only when the `secrets` key of that step names it. The command does not get it. storm shows the value as `<token>` in all that it prints and writes. storm does not write the value to a file. A step can leave the value in the sandbox, and a runner snapshot then keeps it. Do not let a step leave the value.
|
|
23
23
|
- A **run log** is a log in the run directory. The **command log** (`command`) holds all the output of the command. It also holds output that no test owns: output from a `beforeAll`, a global setup, a raw `process.stdout.write`, or a child process. A **step log** (`install`, `build`, `apply`, `snapshot`) holds the output of one step of a sandboxed run.
|
|
24
24
|
|
|
25
25
|
## Commands
|
|
26
26
|
|
|
27
|
-
- `storm vitest [<vitest run args>...] [-- <vitest dash options>...]`
|
|
28
|
-
- `storm playwright [<playwright test args>...] [-- <playwright dash options>...]`
|
|
27
|
+
- `storm vitest [--count-tests] [<vitest run args>...] [-- <vitest dash options>...]` runs `vitest run` with the arguments, after it counts the test files when `storm.config.ts` sets `testPlan`. Put the dash options of vitest, such as `-t` or `--project`, after `--`. The count applies the file filters and `--project`, but not `-t`. A `-t` that matches no test does not stop the run: vitest skips every test and exits 0. Add `--count-tests` to count each test too, with or without `testPlan`. Then the run stops with `no_matching_tests` when no test matches. This count imports every test file, so it is slow for a large suite.
|
|
28
|
+
- `storm playwright [<playwright test args>...] [-- <playwright dash options>...]` runs `playwright test` with the arguments, after it counts the tests when `storm.config.ts` sets `testPlan`. Put the dash options of Playwright, such as `--project` or `--grep`, after `--`.
|
|
29
29
|
- `storm exec -- <command>` runs a different command. It does not count tests.
|
|
30
30
|
- `storm runs list --json` lists the recent runs.
|
|
31
31
|
- `storm runs show <run-id> --json` shows a run, the test plan of a `storm vitest` or `storm playwright` run, its test results, and with `--failed` or `--test` the errors and test output of tests.
|
|
@@ -34,4 +34,4 @@ commands: all
|
|
|
34
34
|
## Other skills
|
|
35
35
|
|
|
36
36
|
- To read the output and the errors of a run, run `storm skills get read-run-output`.
|
|
37
|
-
- To see all the skills, run `storm skills list`.
|
|
37
|
+
- To see all the skills, run `storm skills list`.
|
|
@@ -49,25 +49,24 @@ In a sandboxed run, storm installs and builds before it runs the command.
|
|
|
49
49
|
|
|
50
50
|
## 6. Read why the setup was fast or slow
|
|
51
51
|
|
|
52
|
-
In a sandboxed run, the runner sandbox starts from a runner snapshot: a base snapshot, or a
|
|
52
|
+
In a sandboxed run, the runner sandbox starts from a runner snapshot: a base snapshot at the merge-base, or one at a commit on the branch that `storm snapshots build --base` built. The snapshot decides how much the run uploads, installs and builds.
|
|
53
53
|
|
|
54
54
|
1. Run `storm runs show <run-id> --json`. Read `where.snapshot`.
|
|
55
|
-
2. Read `
|
|
56
|
-
3. Read `builtBehind`: how many commits HEAD has after `
|
|
57
|
-
4. Read `where.uploadBytes`: how many bytes of changes the run uploaded on top of the snapshot's base
|
|
55
|
+
2. Read `base`: the commit the snapshot was built at.
|
|
56
|
+
3. Read `builtBehind`: how many commits HEAD has after `base`, the run's merge-base. A large number means more work for the install and build.
|
|
57
|
+
4. Read `where.uploadBytes`: how many bytes of changes the run uploaded on top of the snapshot's base. The run's merge-base is `where.base`.
|
|
58
58
|
5. Read `built`. If it is `true`, the run built a base snapshot first, which takes a few minutes.
|
|
59
|
-
6.
|
|
60
|
-
7. To
|
|
61
|
-
8. To build that snapshot before the next run, without a test run, run `storm snapshots build --json`. Read `outcome`: `built` or `up_to_date`.
|
|
59
|
+
6. To see which snapshot the next run here starts from, and why it does not start from each other one, run `storm snapshots list --json`. Read `snapshots`: the one with `picked` `true` is the snapshot, and `reason` says why each other one is not. When none has `picked` `true`, a run here builds a base snapshot at the merge-base. A snapshot with `reason` `other-base` has a base that is not the merge-base, so no run here starts from it: a run starts only from a snapshot at its merge-base.
|
|
60
|
+
7. To build a base snapshot before the next run, without a test run, run `storm snapshots build --json`. Read `outcome`: `built` or `up_to_date`.
|
|
62
61
|
|
|
63
62
|
A field is `null` when storm does not know it, such as in a run that an older storm recorded.
|
|
64
63
|
|
|
65
64
|
## 7. Run one test again in the runner sandbox
|
|
66
65
|
|
|
67
|
-
A sandboxed run can keep its runner sandbox running after it ends
|
|
66
|
+
A sandboxed run can keep its runner sandbox running after it ends, for the keep time.
|
|
68
67
|
|
|
69
68
|
1. Run `storm runs show <run-id> --json`.
|
|
70
|
-
2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`, and add `--keep-sandbox 30m`. With that flag, the run
|
|
69
|
+
2. Read `where.keptMinutesLeft`. If it is `null` or 0, the runner sandbox is not running. Start a new run with `storm vitest` or `storm exec`, and add `--keep-sandbox 30m`. With that flag, the run keeps its runner sandbox for 30 minutes.
|
|
71
70
|
3. Read `where.sandboxUrl`. Give a person the Connect page, `<sandboxUrl>/connect`. In it, a person can run one test again.
|
|
72
71
|
|
|
73
72
|
## 8. Read what a resource could not do
|