@ultimat3/testing 30.9.0 → 31.1.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/CLAUDE.md +46 -55
- package/README.md +179 -39
- package/package.json +23 -17
- package/src/ai-conformance-answer.ts +67 -0
- package/src/ai-gateway-conformance.ts +105 -0
- package/src/ai-provider-conformance.ts +69 -0
- package/src/ai-provider-transport-conformance.ts +170 -0
- package/src/audit-sink-conformance.ts +204 -0
- package/src/auth-adapter-conformance-credentials.ts +124 -0
- package/src/auth-adapter-conformance-mfa.ts +70 -0
- package/src/auth-adapter-conformance-passkeys.ts +133 -0
- package/src/auth-adapter-conformance-sessions.ts +115 -0
- package/src/auth-adapter-conformance-support.ts +71 -0
- package/src/auth-adapter-conformance-users.ts +128 -0
- package/src/auth-adapter-conformance.ts +34 -0
- package/src/auth-limiter-factory-conformance.ts +224 -0
- package/src/auth-server-store-conformance-records.ts +69 -0
- package/src/auth-server-store-conformance.ts +208 -0
- package/src/cache-tier-conformance-checks.ts +142 -0
- package/src/cache-tier-conformance.ts +24 -0
- package/src/cassette-format.ts +8 -13
- package/src/cassette-record.ts +1 -1
- package/src/cdp-browser.ts +10 -11
- package/src/cdp-e2e-page.ts +2 -2
- package/src/cdp-e2e-session.ts +2 -2
- package/src/cdp-network-probe.ts +1 -1
- package/src/cdp-offline-script.ts +2 -2
- package/src/clock-conformance.ts +126 -0
- package/src/conformance.ts +239 -0
- package/src/e2e-browser-handle.ts +1 -2
- package/src/e2e-error-codes.ts +17 -16
- package/src/e2e-run.ts +4 -3
- package/src/embedder-conformance.ts +101 -0
- package/src/entity-conformance-aggregates.ts +210 -0
- package/src/entity-conformance-batches.ts +216 -0
- package/src/entity-conformance-bulk.ts +379 -0
- package/src/entity-conformance-checks.ts +27 -0
- package/src/entity-conformance-entities.ts +52 -0
- package/src/entity-conformance-locks.ts +286 -0
- package/src/entity-conformance-matrix.ts +397 -0
- package/src/entity-conformance-reads.ts +241 -0
- package/src/entity-conformance-support.ts +56 -0
- package/src/entity-conformance-tenancy.ts +296 -0
- package/src/entity-conformance-values.ts +305 -0
- package/src/entity-conformance-versions.ts +60 -0
- package/src/entity-conformance-writes.ts +348 -0
- package/src/entity-driver-conformance.ts +103 -0
- package/src/error-groups-store-conformance.ts +198 -0
- package/src/error-reporter-conformance.ts +119 -0
- package/src/errors.ts +20 -2
- package/src/event-bus-conformance.ts +161 -0
- package/src/exercise-drift-hint.ts +4 -1
- package/src/exercise-judge.ts +5 -3
- package/src/exercise-override-line.ts +98 -0
- package/src/exercise-report.ts +138 -115
- package/src/exercise-room-mail.ts +40 -0
- package/src/exercise.ts +33 -29
- package/src/factories.ts +192 -179
- package/src/factory-api.ts +131 -0
- package/src/factory-associations.ts +67 -0
- package/src/factory-errors.ts +38 -0
- package/src/factory-lint.ts +92 -0
- package/src/factory-persist.ts +74 -16
- package/src/factory-pipeline.ts +191 -0
- package/src/factory-registry.ts +2 -1
- package/src/factory-types.ts +131 -0
- package/src/failure-store-conformance.ts +137 -0
- package/src/fixture-jobs.ts +27 -11
- package/src/fixture-mail.ts +7 -7
- package/src/fixture-seed.ts +111 -0
- package/src/fixture-statements.ts +68 -52
- package/src/framework-fixtures.ts +1 -1
- package/src/idempotency-store-conformance.ts +186 -0
- package/src/idempotency-store-replay-conformance.ts +140 -0
- package/src/idempotency-store-tx-conformance.ts +132 -0
- package/src/idempotency-store-world-conformance.ts +82 -0
- package/src/identity-provider-conformance.ts +144 -0
- package/src/image-transform-conformance.ts +89 -0
- package/src/index.ts +68 -157
- package/src/isr-store-conformance.ts +113 -0
- package/src/job-sim-effects.ts +19 -31
- package/src/job-sim-world.ts +6 -15
- package/src/lease-store-conformance.ts +195 -0
- package/src/mail-driver-conformance.ts +108 -0
- package/src/matcher-doubles.ts +104 -0
- package/src/matcher-stub.ts +78 -0
- package/src/matcher-surface.ts +21 -0
- package/src/matchers.ts +19 -1
- package/src/mcp-confirmation-store-conformance.ts +262 -0
- package/src/meter-store-conformance.ts +135 -0
- package/src/notify-digest-conformance.ts +133 -0
- package/src/notify-inbox-conformance.ts +130 -0
- package/src/notify-ledger-conformance.ts +134 -0
- package/src/notify-preference-conformance.ts +49 -0
- package/src/notify-stores-conformance.ts +73 -0
- package/src/outbox-store-conformance-claims.ts +112 -0
- package/src/outbox-store-conformance-subject.ts +65 -0
- package/src/outbox-store-conformance.ts +71 -0
- package/src/per-test-reset.ts +55 -20
- package/src/preload.ts +4 -2
- package/src/purge-conformance.ts +79 -0
- package/src/push-device-conformance.ts +124 -0
- package/src/push-subscription-conformance.ts +123 -0
- package/src/quiet-logs.ts +4 -4
- package/src/rate-limit-store-conformance.ts +178 -0
- package/src/registry-leak-error.ts +8 -1
- package/src/scale-sweep-run.ts +6 -9
- package/src/scrape-driver-conformance-frame-checks.ts +97 -0
- package/src/scrape-driver-conformance-page-checks.ts +114 -0
- package/src/scrape-driver-conformance-site.ts +84 -0
- package/src/scrape-driver-conformance.ts +34 -0
- package/src/sealed-network.ts +20 -2
- package/src/search-index-conformance-list.ts +76 -0
- package/src/search-index-conformance-support.ts +69 -0
- package/src/search-index-conformance-versions.ts +66 -0
- package/src/search-index-conformance.ts +126 -0
- package/src/secret-source-conformance.ts +91 -0
- package/src/seed-factories.ts +57 -0
- package/src/seed-writer.ts +8 -19
- package/src/semantic-cache-factory-conformance.ts +86 -0
- package/src/sms-transport-conformance.ts +102 -0
- package/src/step-store-conformance.ts +171 -0
- package/src/storage-conformance-read-checks.ts +132 -0
- package/src/storage-conformance-shape.ts +121 -0
- package/src/storage-conformance-stream-checks.ts +226 -0
- package/src/storage-conformance.ts +34 -0
- package/src/stub-action.ts +24 -0
- package/src/stub-errors.ts +86 -0
- package/src/stub-job.ts +30 -0
- package/src/stub-query.ts +25 -0
- package/src/stub-script.ts +76 -0
- package/src/stub-stack.ts +29 -0
- package/src/stub.ts +73 -0
- package/src/swap-adapter.ts +135 -0
- package/src/test-scope.ts +96 -0
- package/src/test-types.ts +1 -1
- package/src/totp-replay-guard-conformance.ts +76 -0
- package/src/transport-conformance.ts +179 -0
- package/src/upload-scanner-conformance.ts +112 -0
- package/src/vector-store-conformance-checks.ts +174 -0
- package/src/vector-store-conformance.ts +21 -0
- package/src/cdp-connection.ts +0 -291
- package/src/cdp-errors.ts +0 -179
- package/src/cdp-launch-attempt.ts +0 -224
- package/src/cdp-launch-candidates.ts +0 -62
- package/src/cdp-launch-profile.ts +0 -106
- package/src/cdp-launch-reap.ts +0 -68
- package/src/cdp-launch-wire.ts +0 -171
- package/src/cdp-launch.ts +0 -175
- package/src/cdp-pipe.ts +0 -77
- package/src/cdp-wire-watch.ts +0 -113
package/src/cdp-launch.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// One responsibility: WHICH Chrome, with which flags, and how many starts it gets — the candidate
|
|
2
|
-
// list, the launch deadline and the one relaunch. One start of the process is
|
|
3
|
-
// `cdp-launch-attempt.ts`; the connection is `cdp-connection.ts`, the page `cdp-e2e-page.ts`.
|
|
4
|
-
|
|
5
|
-
import { finiteCount } from '@ultimat3/core';
|
|
6
|
-
import type { CdpLaunchAttempt } from './cdp-errors';
|
|
7
|
-
import { CdpBrowserMissingError, CdpLaunchFailedError } from './cdp-errors';
|
|
8
|
-
import type { LaunchedBrowser } from './cdp-launch-attempt';
|
|
9
|
-
import { LAUNCH_REAP_MS, launchAttempt } from './cdp-launch-attempt';
|
|
10
|
-
import { chromeCandidates } from './cdp-launch-candidates';
|
|
11
|
-
import type { CdpWire } from './cdp-launch-wire';
|
|
12
|
-
import { defaultWire, wireFlag } from './cdp-launch-wire';
|
|
13
|
-
|
|
14
|
-
export type { LaunchedBrowser } from './cdp-launch-attempt';
|
|
15
|
-
export { CLOSE_GRACE_MS, LAUNCH_REAP_MS } from './cdp-launch-attempt';
|
|
16
|
-
export { chromeCandidates } from './cdp-launch-candidates';
|
|
17
|
-
export type { CdpWire } from './cdp-launch-wire';
|
|
18
|
-
export { defaultWire } from './cdp-launch-wire';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Where a Chrome is, in the order worth trying. `CHROME_PATH` first because it is the operator's
|
|
22
|
-
* answer and the only one that can be right on a machine none of the rest describes; after it, the
|
|
23
|
-
* install locations of THIS platform (`cdp-launch-candidates.ts`) — on Linux the `/usr/bin` names
|
|
24
|
-
* GitHub-hosted `ubuntu-latest` ships, which is what lets the browser-backed suite run in CI with
|
|
25
|
-
* **no download step and no new dependency**; on Windows Chrome and Edge; on macOS the app bundles.
|
|
26
|
-
*/
|
|
27
|
-
export const CHROME_PATH_ENV = 'CHROME_PATH';
|
|
28
|
-
export const CHROME_CANDIDATES: readonly string[] = chromeCandidates(process.platform, process.env);
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The first candidate that exists, or `undefined`. An absent browser is a SKIP, never a failure.
|
|
32
|
-
* `platform` is a parameter so the Windows and macOS lists are asserted on a Linux runner too.
|
|
33
|
-
*/
|
|
34
|
-
export async function findChrome(
|
|
35
|
-
env: Readonly<Record<string, string | undefined>>,
|
|
36
|
-
platform: string = process.platform,
|
|
37
|
-
): Promise<string | undefined> {
|
|
38
|
-
const declared = env[CHROME_PATH_ENV];
|
|
39
|
-
const candidates =
|
|
40
|
-
declared === undefined || declared === '' ? chromeCandidates(platform, env) : [declared];
|
|
41
|
-
for (const candidate of candidates) {
|
|
42
|
-
if (await Bun.file(candidate).exists()) return candidate;
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The two flags a CONTAINER needs, regardless of which process launches Chrome: the sandbox needs
|
|
49
|
-
* privileges CI (and an Ubuntu 23.10+ host with AppArmor's unprivileged-user-namespace restriction
|
|
50
|
-
* — Chrome exits "No usable sandbox" there with neither) does not grant, and `/dev/shm` is 64 MB in
|
|
51
|
-
* a default container, which crashes the renderer on any real page.
|
|
52
|
-
*
|
|
53
|
-
* Exported, and in `chromeLaunchFlags` below, so every launcher carries the SAME two. `x shot` had
|
|
54
|
-
* neither while it launched through `puppeteer-core`, so a box where `x verify`'s e2e gate ran green
|
|
55
|
-
* could not run `x shot` at all; since 22.0.0 it launches through `launchChrome` here.
|
|
56
|
-
*/
|
|
57
|
-
export const CONTAINER_CHROME_ARGS: readonly string[] = ['--no-sandbox', '--disable-dev-shm-usage'];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The flags, and every one of them earns its line.
|
|
61
|
-
*
|
|
62
|
-
* `--headless=new` is Chrome's own headless rather than the retired shim. The wire flag is
|
|
63
|
-
* `--remote-debugging-pipe` wherever the pipe can be held (`cdp-pipe.ts` says why it is not the
|
|
64
|
-
* WebSocket): no port, so two suites on one machine can never collide, and nothing but this process
|
|
65
|
-
* can drive the browser — and `--remote-debugging-port=0` on Windows (`cdp-launch-wire.ts`). A
|
|
66
|
-
* throwaway `--user-data-dir` because a run sharing a profile with a real browser inherits its
|
|
67
|
-
* cookies and locks its files.
|
|
68
|
-
*/
|
|
69
|
-
export const chromeLaunchFlags = (
|
|
70
|
-
profileDir: string,
|
|
71
|
-
wire: CdpWire = defaultWire(process.platform),
|
|
72
|
-
): readonly string[] => [
|
|
73
|
-
'--headless=new',
|
|
74
|
-
wireFlag(wire),
|
|
75
|
-
`--user-data-dir=${profileDir}`,
|
|
76
|
-
...CONTAINER_CHROME_ARGS,
|
|
77
|
-
'--disable-gpu',
|
|
78
|
-
// The cookie store's encryption key comes from the OS keyring, asked over D-Bus on the first
|
|
79
|
-
// cookie access — which is the first navigation. With no keyring answering, Chrome waits out the
|
|
80
|
-
// D-Bus timeout: measured 7-25 s on the first `Page.navigate` of every launch, against a 30 s CDP
|
|
81
|
-
// deadline, which is the intermittent `X_CDP_TIMEOUT` of a full e2e run. A throwaway profile has
|
|
82
|
-
// no secret worth a keyring. `x shot` launches through here too, so it has both.
|
|
83
|
-
'--password-store=basic',
|
|
84
|
-
'--use-mock-keychain',
|
|
85
|
-
// Nothing here should reach the network on its own account, and a first-run bubble or an update
|
|
86
|
-
// check is a page load the test did not ask for.
|
|
87
|
-
'--no-first-run',
|
|
88
|
-
'--no-default-browser-check',
|
|
89
|
-
'--disable-extensions',
|
|
90
|
-
// `--disable-extensions` leaves Google Chrome's COMPONENT extensions running, each with a page of
|
|
91
|
-
// its own: the hangouts one (nkeimhogjdpnpccoofpliimaahmaaome) loads `thunk.js` while the browser
|
|
92
|
-
// starts, and `x shot`'s browser-wide interception paused it and logged it as an off-list request
|
|
93
|
-
// of the page under test (CI, 2026-10-09). A test browser runs no page it was not handed.
|
|
94
|
-
'--disable-component-extensions-with-background-pages',
|
|
95
|
-
'about:blank',
|
|
96
|
-
];
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* How long a COLD start may take before the browser is given up on. Its own number, never the
|
|
100
|
-
* per-call deadline: measured 2026-10-02 over `scaffold-smoke` on free `ubuntu-latest` runners, the
|
|
101
|
-
* first launch of a job cost 5-19 s more than a warm one in 11 green jobs, and the one red job was
|
|
102
|
-
* still printing start-up lines when a 30 s deadline killed it. Twice that, and finite: a browser
|
|
103
|
-
* that exits says so at once (its pipe closes), so only one alive and silent waits this long.
|
|
104
|
-
*/
|
|
105
|
-
export const LAUNCH_TIMEOUT_MS = 60_000;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Starts per launch: the first, and ONE more on a fresh profile after the first was reaped. A
|
|
109
|
-
* process start is the one step here whose failure can belong to the machine rather than the
|
|
110
|
-
* binary — and the second start of a cold binary is a warm one. Never a loop: two starts that both
|
|
111
|
-
* went unanswered are `X_CDP_LAUNCH_FAILED` carrying both.
|
|
112
|
-
*/
|
|
113
|
-
export const LAUNCH_ATTEMPTS = 2;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* The longest `launchChrome` is DESIGNED to take, for any `timeoutMs` up to `LAUNCH_TIMEOUT_MS`:
|
|
117
|
-
* every start given its whole deadline, each failed one its bounded reap. A hook that wraps a launch
|
|
118
|
-
* and gives it less is killed by Bun before the relaunch, and the `X_CDP_LAUNCH_FAILED` that would
|
|
119
|
-
* have named the slow step never surfaces — the shape of four CI flakes (plan 101, F1).
|
|
120
|
-
*/
|
|
121
|
-
export const LAUNCH_BUDGET_MS = LAUNCH_ATTEMPTS * (LAUNCH_TIMEOUT_MS + LAUNCH_REAP_MS);
|
|
122
|
-
|
|
123
|
-
export interface LaunchOptions {
|
|
124
|
-
readonly executable: string;
|
|
125
|
-
/** Every CDP call's deadline once the browser is up. */
|
|
126
|
-
readonly timeoutMs: number;
|
|
127
|
-
/** The first answer's deadline, per start. Defaults to the larger of `timeoutMs` and `LAUNCH_TIMEOUT_MS`. */
|
|
128
|
-
readonly launchTimeoutMs?: number | undefined;
|
|
129
|
-
/** The wire. Defaults to this platform's (`defaultWire`): the pipe, and on Windows the port. */
|
|
130
|
-
readonly wire?: CdpWire | undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Start Chrome on a throwaway profile and answer once it has answered one CDP call. A browser that
|
|
135
|
-
* dies or stays silent is started once more; twice is `X_CDP_LAUNCH_FAILED` with each start's own
|
|
136
|
-
* stderr and whether it exited or was killed at the deadline.
|
|
137
|
-
*/
|
|
138
|
-
export async function launchChrome(options: LaunchOptions): Promise<LaunchedBrowser> {
|
|
139
|
-
// Screened: `setTimeout(fn, NaN)` fires in 1 ms, which reports a healthy browser as silent.
|
|
140
|
-
const launchTimeoutMs = finiteCount(
|
|
141
|
-
'launchChrome',
|
|
142
|
-
'launchTimeoutMs',
|
|
143
|
-
options.launchTimeoutMs ?? Math.max(options.timeoutMs, LAUNCH_TIMEOUT_MS),
|
|
144
|
-
1,
|
|
145
|
-
);
|
|
146
|
-
const wire = options.wire ?? defaultWire(process.platform);
|
|
147
|
-
const failures: CdpLaunchAttempt[] = [];
|
|
148
|
-
while (failures.length < LAUNCH_ATTEMPTS) {
|
|
149
|
-
const started = await launchAttempt({
|
|
150
|
-
executable: options.executable,
|
|
151
|
-
flags: (profileDir) => chromeLaunchFlags(profileDir, wire),
|
|
152
|
-
wire,
|
|
153
|
-
timeoutMs: options.timeoutMs,
|
|
154
|
-
launchTimeoutMs,
|
|
155
|
-
});
|
|
156
|
-
if (started.ok) return started.browser;
|
|
157
|
-
failures.push(started.failure);
|
|
158
|
-
// A process that outlived SIGKILL's grace still holds the machine; a second beside it is the
|
|
159
|
-
// load that made the first one late.
|
|
160
|
-
if (!started.reaped) break;
|
|
161
|
-
}
|
|
162
|
-
throw new CdpLaunchFailedError({ executable: options.executable, attempts: failures });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** `findChrome` then `launchChrome`. Refuses by name when there is no browser to drive. */
|
|
166
|
-
export async function launchFoundChrome(
|
|
167
|
-
env: Readonly<Record<string, string | undefined>>,
|
|
168
|
-
timeoutMs: number,
|
|
169
|
-
): Promise<LaunchedBrowser> {
|
|
170
|
-
const executable = await findChrome(env);
|
|
171
|
-
if (executable === undefined) {
|
|
172
|
-
throw new CdpBrowserMissingError({ tried: chromeCandidates(process.platform, env) });
|
|
173
|
-
}
|
|
174
|
-
return launchChrome({ executable, timeoutMs });
|
|
175
|
-
}
|
package/src/cdp-pipe.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// One responsibility: CDP over the pipe `--remote-debugging-pipe` opens — Chrome reads commands on
|
|
2
|
-
// its fd 3 and writes replies and events on its fd 4, each message one JSON text ended by a NUL
|
|
3
|
-
// byte. This is the e2e driver's wire; the WebSocket in `cdp-connection.ts` is for a remote browser.
|
|
4
|
-
//
|
|
5
|
-
// Why a pipe rather than the WebSocket Chrome also offers: Bun 1.4.0's WebSocket client handed
|
|
6
|
-
// `onmessage` text spliced from several frames under the dummy's `offline-feed` load — 64
|
|
7
|
-
// unparseable frames in one run, one of them a `Runtime.evaluate` reply that then waited out its
|
|
8
|
-
// 30 s deadline. A frame nobody can parse has no `id`, so no layer above can even tell which call
|
|
9
|
-
// it lost. A pipe is bytes and a delimiter, read here, and nothing in between.
|
|
10
|
-
|
|
11
|
-
import type { CdpTransport } from './cdp-connection';
|
|
12
|
-
|
|
13
|
-
/** The two ends a transport needs: a sink for whole messages, and the byte stream Chrome writes. */
|
|
14
|
-
export interface PipeEnds {
|
|
15
|
-
/** Write these bytes to Chrome's fd 3, in order. */
|
|
16
|
-
readonly write: (bytes: Uint8Array) => void;
|
|
17
|
-
/** Chrome's fd 4. */
|
|
18
|
-
readonly read: ReadableStream<Uint8Array>;
|
|
19
|
-
/** Release the write end — Chrome treats its fd 3 closing as the client going away. */
|
|
20
|
-
readonly end: () => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const NUL = 0;
|
|
24
|
-
|
|
25
|
-
/** Concatenate two byte arrays; the reader only ever holds the unterminated tail. */
|
|
26
|
-
const join = (a: Uint8Array, b: Uint8Array): Uint8Array => {
|
|
27
|
-
if (a.length === 0) return b;
|
|
28
|
-
const out = new Uint8Array(a.length + b.length);
|
|
29
|
-
out.set(a);
|
|
30
|
-
out.set(b, a.length);
|
|
31
|
-
return out;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export function pipeTransport(ends: PipeEnds): CdpTransport {
|
|
35
|
-
const encoder = new TextEncoder();
|
|
36
|
-
let closed = false;
|
|
37
|
-
const reader = ends.read.getReader();
|
|
38
|
-
return {
|
|
39
|
-
send(text: string): void {
|
|
40
|
-
if (closed) return;
|
|
41
|
-
const body = encoder.encode(text);
|
|
42
|
-
const framed = new Uint8Array(body.length + 1);
|
|
43
|
-
framed.set(body);
|
|
44
|
-
framed[body.length] = NUL;
|
|
45
|
-
ends.write(framed);
|
|
46
|
-
},
|
|
47
|
-
close(): void {
|
|
48
|
-
if (closed) return;
|
|
49
|
-
closed = true;
|
|
50
|
-
ends.end();
|
|
51
|
-
void reader.cancel().catch(() => undefined);
|
|
52
|
-
},
|
|
53
|
-
listen(handlers): void {
|
|
54
|
-
void (async () => {
|
|
55
|
-
// Split on BYTES, decoded per message: a multi-byte character may straddle two reads, and
|
|
56
|
-
// decoding each read on its own would corrupt it — the failure this file exists to end.
|
|
57
|
-
const decoder = new TextDecoder();
|
|
58
|
-
let tail: Uint8Array = new Uint8Array(0);
|
|
59
|
-
try {
|
|
60
|
-
for (;;) {
|
|
61
|
-
const { value, done } = await reader.read();
|
|
62
|
-
if (done) break;
|
|
63
|
-
tail = join(tail, value);
|
|
64
|
-
for (let at = tail.indexOf(NUL); at !== -1; at = tail.indexOf(NUL)) {
|
|
65
|
-
handlers.message(decoder.decode(tail.subarray(0, at)));
|
|
66
|
-
tail = tail.subarray(at + 1);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch {
|
|
70
|
-
// A read that fails is a pipe that is gone — reported as the close it is, below.
|
|
71
|
-
}
|
|
72
|
-
closed = true;
|
|
73
|
-
handlers.closed('the browser closed the CDP pipe');
|
|
74
|
-
})();
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/cdp-wire-watch.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// One responsibility: remember what the wire did, so a call that is never answered can say WHY —
|
|
2
|
-
// its target went away, frames arrived that nothing could parse, or the target simply stayed
|
|
3
|
-
// silent. The connection (`cdp-connection.ts`) feeds every frame in; `CdpTimeoutError` reads it out.
|
|
4
|
-
|
|
5
|
-
import type { CdpTargetGone, CdpTimeoutObservation } from './cdp-errors';
|
|
6
|
-
|
|
7
|
-
/** How many of the latest frames a timeout quotes. Bounded: a busy page sends thousands. */
|
|
8
|
-
export const LAST_FRAMES = 8;
|
|
9
|
-
|
|
10
|
-
/** Where the wire stood when a call was sent — what "since the call" is measured from. */
|
|
11
|
-
export interface WireMark {
|
|
12
|
-
readonly arrived: number;
|
|
13
|
-
readonly dropped: number;
|
|
14
|
-
readonly navigations: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface WireWatch {
|
|
18
|
-
/** One frame that parsed: a reply or an event. */
|
|
19
|
-
frame(frame: Record<string, unknown>): void;
|
|
20
|
-
/** One frame nothing could parse. It has no `id`, so no call can be failed with it — only counted. */
|
|
21
|
-
drop(): void;
|
|
22
|
-
mark(sessionId: string | undefined): WireMark;
|
|
23
|
-
/** What happened between `mark` and now, for the call sent on `sessionId`. */
|
|
24
|
-
observe(mark: WireMark, sessionId: string | undefined, open: boolean): CdpTimeoutObservation;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const text = (from: unknown, key: string): string | undefined => {
|
|
28
|
-
const value =
|
|
29
|
-
typeof from === 'object' && from !== null ? (from as Record<string, unknown>)[key] : undefined;
|
|
30
|
-
return typeof value === 'string' ? value : undefined;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function wireWatch(): WireWatch {
|
|
34
|
-
let arrived = 0;
|
|
35
|
-
let dropped = 0;
|
|
36
|
-
const last: string[] = [];
|
|
37
|
-
const targetOf = new Map<string, string>(); // sessionId → targetId
|
|
38
|
-
const gone = new Map<string, CdpTargetGone>(); // sessionId → how it went
|
|
39
|
-
const navigations = new Map<string, number>(); // sessionId → main-frame navigations
|
|
40
|
-
|
|
41
|
-
const goneTarget = (targetId: string | undefined, how: CdpTargetGone): void => {
|
|
42
|
-
for (const [session, target] of targetOf) if (target === targetId) gone.set(session, how);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** The few events that say a session can no longer answer, or that its page was replaced. */
|
|
46
|
-
const track = (method: string, session: string | undefined, params: unknown): void => {
|
|
47
|
-
if (method === 'Target.attachedToTarget') {
|
|
48
|
-
const attached = text(params, 'sessionId');
|
|
49
|
-
const target = text(
|
|
50
|
-
(params as Record<string, unknown> | undefined)?.['targetInfo'],
|
|
51
|
-
'targetId',
|
|
52
|
-
);
|
|
53
|
-
if (attached !== undefined && target !== undefined) targetOf.set(attached, target);
|
|
54
|
-
} else if (method === 'Target.detachedFromTarget') {
|
|
55
|
-
const detached = text(params, 'sessionId');
|
|
56
|
-
if (detached !== undefined) gone.set(detached, 'detached');
|
|
57
|
-
} else if (method === 'Target.targetDestroyed') {
|
|
58
|
-
goneTarget(text(params, 'targetId'), 'destroyed');
|
|
59
|
-
} else if (method === 'Target.targetCrashed') {
|
|
60
|
-
goneTarget(text(params, 'targetId'), 'crashed');
|
|
61
|
-
} else if (method === 'Inspector.targetCrashed' && session !== undefined) {
|
|
62
|
-
gone.set(session, 'crashed');
|
|
63
|
-
} else if (method === 'Page.frameNavigated' && session !== undefined) {
|
|
64
|
-
const frame = (params as Record<string, unknown> | undefined)?.['frame'];
|
|
65
|
-
// A frame with a parent is an iframe: the document the call was sent to is still there.
|
|
66
|
-
if (text(frame, 'parentId') === undefined) {
|
|
67
|
-
navigations.set(session, (navigations.get(session) ?? 0) + 1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const note = (label: string): void => {
|
|
73
|
-
last.push(label);
|
|
74
|
-
if (last.length > LAST_FRAMES) last.shift();
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
frame(frame): void {
|
|
79
|
-
arrived += 1;
|
|
80
|
-
const session = text(frame, 'sessionId');
|
|
81
|
-
const id = frame['id'];
|
|
82
|
-
const method = text(frame, 'method');
|
|
83
|
-
if (typeof id === 'number') note(`reply ${String(id)}`);
|
|
84
|
-
else if (method === undefined) note('a frame with neither an id nor a method');
|
|
85
|
-
else {
|
|
86
|
-
note(session === undefined ? method : `${method} @${session}`);
|
|
87
|
-
track(method, session, frame['params']);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
drop(): void {
|
|
91
|
-
dropped += 1;
|
|
92
|
-
},
|
|
93
|
-
mark: (sessionId) => ({
|
|
94
|
-
arrived,
|
|
95
|
-
dropped,
|
|
96
|
-
navigations: sessionId === undefined ? 0 : (navigations.get(sessionId) ?? 0),
|
|
97
|
-
}),
|
|
98
|
-
observe(mark, sessionId, open): CdpTimeoutObservation {
|
|
99
|
-
const since = arrived - mark.arrived;
|
|
100
|
-
return {
|
|
101
|
-
sessionId: sessionId ?? null,
|
|
102
|
-
framesArrived: since,
|
|
103
|
-
// Only frames that arrived AFTER the call: an older one says nothing about its reply.
|
|
104
|
-
lastFrames: since === 0 ? [] : last.slice(-Math.min(since, LAST_FRAMES)),
|
|
105
|
-
framesDropped: dropped - mark.dropped,
|
|
106
|
-
transportOpen: open,
|
|
107
|
-
targetGone: sessionId === undefined ? null : (gone.get(sessionId) ?? null),
|
|
108
|
-
navigations:
|
|
109
|
-
sessionId === undefined ? 0 : (navigations.get(sessionId) ?? 0) - mark.navigations,
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|