@cbxss/eoka 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +539 -2
- package/dist/LICENSE +21 -0
- package/dist/browser-install-diagnostics.d.ts +1 -0
- package/dist/browser-install-diagnostics.js +21 -0
- package/dist/browser-install-engine.d.ts +10 -0
- package/dist/browser-install-engine.js +286 -0
- package/dist/browser-install-inventory.d.ts +25 -0
- package/dist/browser-install-inventory.js +101 -0
- package/dist/browser-install-worker.d.ts +21 -0
- package/dist/browser-install-worker.js +65 -0
- package/dist/browser-install.d.ts +22 -0
- package/dist/browser-install.js +7 -0
- package/dist/browser.d.ts +59 -0
- package/dist/browser.js +445 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +44 -0
- package/dist/generated/protocol.d.ts +3901 -0
- package/dist/generated/protocol.js +2 -0
- package/dist/generated/schema-bundle.json +18868 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +11 -0
- package/dist/install-errors.d.ts +4 -0
- package/dist/install-errors.js +6 -0
- package/dist/operations.d.ts +22 -0
- package/dist/operations.js +87 -0
- package/dist/page.d.ts +77 -0
- package/dist/page.js +250 -0
- package/dist/platform.d.ts +4 -0
- package/dist/platform.js +27 -0
- package/dist/recording.d.ts +27 -0
- package/dist/recording.js +124 -0
- package/dist/release-manifest.json +101 -0
- package/dist/release.d.ts +36 -0
- package/dist/release.js +76 -0
- package/dist/server-binary.d.ts +11 -0
- package/dist/server-binary.js +107 -0
- package/dist/transport.d.ts +89 -0
- package/dist/transport.js +737 -0
- package/examples/capture.mjs +36 -0
- package/examples/consume-schema.mjs +7 -0
- package/examples/explicit-paths.mjs +42 -0
- package/examples/install-browser.mjs +20 -0
- package/examples/offline.mjs +20 -0
- package/package.json +70 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isAbsolute, toNamespacedPath } from 'node:path';
|
|
2
|
+
import { EokaError } from './errors.js';
|
|
3
|
+
export function requireCaptureCapability(client, method, capability) {
|
|
4
|
+
if (client.supports?.(method) !== true) {
|
|
5
|
+
throw new EokaError('UnsupportedMethod', `Sidecar does not support ${method}.`, { requestState: 'not_sent' });
|
|
6
|
+
}
|
|
7
|
+
if (client.hasCapability?.(capability) !== true) {
|
|
8
|
+
throw new EokaError('UnsupportedCapability', `Sidecar did not negotiate ${capability}.`, { requestState: 'not_sent' });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class RecordingError extends EokaError {
|
|
12
|
+
recordingId;
|
|
13
|
+
record;
|
|
14
|
+
failure;
|
|
15
|
+
path;
|
|
16
|
+
partialPath;
|
|
17
|
+
cleanupUncertain;
|
|
18
|
+
constructor(code, message, recordingId, record, details = {}, path) {
|
|
19
|
+
super(code, message, details);
|
|
20
|
+
this.recordingId = recordingId;
|
|
21
|
+
this.record = record;
|
|
22
|
+
this.failure = record?.failure ?? undefined;
|
|
23
|
+
const data = details.data;
|
|
24
|
+
this.path = record?.path ?? data?.path ?? path;
|
|
25
|
+
this.partialPath = record?.failure?.partialPath ?? data?.partialPath ?? undefined;
|
|
26
|
+
this.cleanupUncertain = record?.failure?.cleanupUncertain ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function recordingFailure(error, id, record, path, pageId) {
|
|
30
|
+
if (error instanceof RecordingError && error.recordingId === id)
|
|
31
|
+
return error;
|
|
32
|
+
const details = { cause: error };
|
|
33
|
+
if (error instanceof EokaError) {
|
|
34
|
+
if (error.requestId !== undefined)
|
|
35
|
+
details.requestId = error.requestId;
|
|
36
|
+
if (error.operationId !== undefined)
|
|
37
|
+
details.operationId = error.operationId;
|
|
38
|
+
if (error.requestState !== undefined)
|
|
39
|
+
details.requestState = error.requestState;
|
|
40
|
+
if (error.receipt !== undefined)
|
|
41
|
+
details.receipt = error.receipt;
|
|
42
|
+
if (error.data !== undefined)
|
|
43
|
+
details.data = error.data;
|
|
44
|
+
if (error.stderr !== undefined)
|
|
45
|
+
details.stderr = error.stderr;
|
|
46
|
+
const data = error.data;
|
|
47
|
+
if (data?.recording != null) {
|
|
48
|
+
try {
|
|
49
|
+
validateRecordingRecord(data.recording, id, pageId ?? record?.pageId, path ?? record?.path);
|
|
50
|
+
}
|
|
51
|
+
catch (validation) {
|
|
52
|
+
if (!(validation instanceof RecordingError))
|
|
53
|
+
throw validation;
|
|
54
|
+
return new RecordingError(validation.code, validation.message, id, data.recording, details, path);
|
|
55
|
+
}
|
|
56
|
+
record = data.recording;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return new RecordingError(error instanceof EokaError ? error.code : 'RecordingFailed', error instanceof Error ? error.message : String(error), id, record, details, path);
|
|
60
|
+
}
|
|
61
|
+
export function validateRecordingRecord(record, id, pageId, path) {
|
|
62
|
+
if (record.recordingId !== id || (pageId !== undefined && record.pageId !== pageId)
|
|
63
|
+
|| (path !== undefined && record.path !== path
|
|
64
|
+
&& (!isAbsolute(record.path) || !isAbsolute(path) || toNamespacedPath(record.path) !== toNamespacedPath(path)))
|
|
65
|
+
|| (record.state === 'completed' && (record.artifact == null
|
|
66
|
+
|| (record.artifact.path !== record.path
|
|
67
|
+
&& (!isAbsolute(record.artifact.path) || !isAbsolute(record.path) || toNamespacedPath(record.artifact.path) !== toNamespacedPath(record.path)))
|
|
68
|
+
|| record.artifact.container !== 'mp4'
|
|
69
|
+
|| record.artifact.mimeType !== 'video/mp4' || !Number.isSafeInteger(record.artifact.bytes) || record.artifact.bytes <= 0 || record.failure != null))
|
|
70
|
+
|| (record.state !== 'completed' && record.artifact != null)) {
|
|
71
|
+
throw new RecordingError('Protocol', `Received an inconsistent recording record for ${id}.`, id, record, { requestState: 'acknowledged' });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export class Recording {
|
|
75
|
+
id;
|
|
76
|
+
client;
|
|
77
|
+
latest;
|
|
78
|
+
constructor(client, id, record) {
|
|
79
|
+
this.client = client;
|
|
80
|
+
this.id = id;
|
|
81
|
+
if (record !== undefined)
|
|
82
|
+
validateRecordingRecord(record, id);
|
|
83
|
+
this.latest = record;
|
|
84
|
+
}
|
|
85
|
+
get record() { return this.latest; }
|
|
86
|
+
remember(record) {
|
|
87
|
+
if (this.latest === undefined || this.latest.state === 'running' || this.latest.state === 'finalizing' || (record.state !== 'running' && record.state !== 'finalizing')) {
|
|
88
|
+
this.latest = record;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async call(method, options) {
|
|
92
|
+
try {
|
|
93
|
+
requireCaptureCapability(this.client, method, 'nativeRecording');
|
|
94
|
+
const record = await this.client.invoke(method, { recordingId: this.id }, options);
|
|
95
|
+
validateRecordingRecord(record, this.id, this.latest?.pageId, this.latest?.path);
|
|
96
|
+
this.remember(record);
|
|
97
|
+
return record;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
const failure = recordingFailure(error, this.id, this.latest);
|
|
101
|
+
if (failure.code !== 'Protocol' && failure.record?.recordingId === this.id && failure.record.pageId === (this.latest?.pageId ?? failure.record.pageId)) {
|
|
102
|
+
this.remember(failure.record);
|
|
103
|
+
}
|
|
104
|
+
throw failure;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
status(options) {
|
|
108
|
+
return this.call('recording.get', options);
|
|
109
|
+
}
|
|
110
|
+
async stop(options) {
|
|
111
|
+
const record = await this.call('recording.stop', options);
|
|
112
|
+
if (record.state !== 'completed' || record.artifact == null) {
|
|
113
|
+
throw new RecordingError(record.failure?.code ?? 'RecordingInvalidState', record.failure?.message ?? `Recording ${this.id} is ${record.state}; no completed artifact was published.`, this.id, record, { requestState: 'acknowledged' });
|
|
114
|
+
}
|
|
115
|
+
return record.artifact;
|
|
116
|
+
}
|
|
117
|
+
async cancel(options) {
|
|
118
|
+
const record = await this.call('recording.cancel', options);
|
|
119
|
+
if (record.state === 'running' || record.state === 'finalizing') {
|
|
120
|
+
throw new RecordingError('Protocol', `Cancellation of recording ${this.id} returned a nonterminal record.`, this.id, record, { requestState: 'acknowledged' });
|
|
121
|
+
}
|
|
122
|
+
return record;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"sdkVersion": "0.1.0-beta.1",
|
|
4
|
+
"installerVersion": "3.2.4",
|
|
5
|
+
"server": {
|
|
6
|
+
"version": "0.5.0",
|
|
7
|
+
"protocolVersion": "1.3",
|
|
8
|
+
"platforms": {
|
|
9
|
+
"linux-x64-gnu": {
|
|
10
|
+
"packageName": "@cbxss/eoka-server-linux-x64-gnu",
|
|
11
|
+
"packageVersion": "0.1.0-beta.1",
|
|
12
|
+
"target": "x86_64-unknown-linux-gnu",
|
|
13
|
+
"asset": "eoka-server-linux-amd64",
|
|
14
|
+
"executablePath": "bin/eoka-server",
|
|
15
|
+
"sha256": "5eb3ba769d92389626d78f8e6d9917fecfdbb9690da37a6e327cee05818884e3",
|
|
16
|
+
"size": 16897520,
|
|
17
|
+
"minimumGlibc": "2.35",
|
|
18
|
+
"development": false
|
|
19
|
+
},
|
|
20
|
+
"linux-arm64-gnu": {
|
|
21
|
+
"packageName": "@cbxss/eoka-server-linux-arm64-gnu",
|
|
22
|
+
"packageVersion": "0.1.0-beta.1",
|
|
23
|
+
"target": "aarch64-unknown-linux-gnu",
|
|
24
|
+
"asset": "eoka-server-linux-arm64",
|
|
25
|
+
"executablePath": "bin/eoka-server",
|
|
26
|
+
"sha256": "10497b7fe4cdd460ee0c6bb0a54675e3cb3e716e066d895c8533b547107460b8",
|
|
27
|
+
"size": 16210368,
|
|
28
|
+
"minimumGlibc": "2.35",
|
|
29
|
+
"development": false
|
|
30
|
+
},
|
|
31
|
+
"darwin-x64": {
|
|
32
|
+
"packageName": "@cbxss/eoka-server-darwin-x64",
|
|
33
|
+
"packageVersion": "0.1.0-beta.1",
|
|
34
|
+
"target": "x86_64-apple-darwin",
|
|
35
|
+
"asset": "eoka-server-darwin-amd64",
|
|
36
|
+
"executablePath": "bin/eoka-server",
|
|
37
|
+
"sha256": "d5570334ed5f0cc927ec8ad5cebf4fd81b756eee2a6bdde903f75eb706725169",
|
|
38
|
+
"size": 14995968,
|
|
39
|
+
"minimumGlibc": null,
|
|
40
|
+
"development": false
|
|
41
|
+
},
|
|
42
|
+
"darwin-arm64": {
|
|
43
|
+
"packageName": "@cbxss/eoka-server-darwin-arm64",
|
|
44
|
+
"packageVersion": "0.1.0-beta.1",
|
|
45
|
+
"target": "aarch64-apple-darwin",
|
|
46
|
+
"asset": "eoka-server-darwin-arm64",
|
|
47
|
+
"executablePath": "bin/eoka-server",
|
|
48
|
+
"sha256": "2437c1d3835ef9bd3f4cce5f9f6c0120000e791023cffcf552e8ac89d28683f3",
|
|
49
|
+
"size": 14543216,
|
|
50
|
+
"minimumGlibc": null,
|
|
51
|
+
"development": false
|
|
52
|
+
},
|
|
53
|
+
"win32-x64": {
|
|
54
|
+
"packageName": "@cbxss/eoka-server-win32-x64",
|
|
55
|
+
"packageVersion": "0.1.0-beta.1",
|
|
56
|
+
"target": "x86_64-pc-windows-msvc",
|
|
57
|
+
"asset": "eoka-server-windows-amd64.exe",
|
|
58
|
+
"executablePath": "bin/eoka-server.exe",
|
|
59
|
+
"sha256": "e3a13dcdedaba1ad4d1fb85c6a1a71ab5dab7a906d4d980161541fc2afe9f743",
|
|
60
|
+
"size": 14008320,
|
|
61
|
+
"minimumGlibc": null,
|
|
62
|
+
"development": false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"chrome": {
|
|
67
|
+
"buildId": "155.0.8059.39",
|
|
68
|
+
"platforms": {
|
|
69
|
+
"linux-x64-gnu": {
|
|
70
|
+
"platform": "linux",
|
|
71
|
+
"url": "https://storage.googleapis.com/chrome-for-testing-public/155.0.8059.39/linux64/chrome-linux64.zip",
|
|
72
|
+
"sha256": "55672d1f392fd3e7b7a08621b6e804e6bcb39d40cf155504abb74b3a021ea8ea",
|
|
73
|
+
"executablePath": "chrome-linux64/chrome"
|
|
74
|
+
},
|
|
75
|
+
"linux-arm64-gnu": {
|
|
76
|
+
"platform": "linux_arm",
|
|
77
|
+
"url": "https://storage.googleapis.com/chrome-for-testing-public/155.0.8059.39/linux-arm64/chrome-linux-arm64.zip",
|
|
78
|
+
"sha256": "b9d44e5d183260ca941a4c4d8d21c8a437d81ef778a489047ef98968b0475dc5",
|
|
79
|
+
"executablePath": "chrome-linux-arm64/chrome"
|
|
80
|
+
},
|
|
81
|
+
"darwin-x64": {
|
|
82
|
+
"platform": "mac",
|
|
83
|
+
"url": "https://storage.googleapis.com/chrome-for-testing-public/155.0.8059.39/mac-x64/chrome-mac-x64.zip",
|
|
84
|
+
"sha256": "9e4da7961d4a426078f02e89ecfa569a7926ada2dc88aa53c0bd9ed0d46c3bb7",
|
|
85
|
+
"executablePath": "chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
|
|
86
|
+
},
|
|
87
|
+
"darwin-arm64": {
|
|
88
|
+
"platform": "mac_arm",
|
|
89
|
+
"url": "https://storage.googleapis.com/chrome-for-testing-public/155.0.8059.39/mac-arm64/chrome-mac-arm64.zip",
|
|
90
|
+
"sha256": "529a71bd61aaa2ef266a4d4bd300ae9572ba6a3468a8d55c3023ffeffb5b6b4e",
|
|
91
|
+
"executablePath": "chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
|
|
92
|
+
},
|
|
93
|
+
"win32-x64": {
|
|
94
|
+
"platform": "win64",
|
|
95
|
+
"url": "https://storage.googleapis.com/chrome-for-testing-public/155.0.8059.39/win64/chrome-win64.zip",
|
|
96
|
+
"sha256": "59ab2a6e99bde9c0bc180414988394f9f5355a0d3764c704151ee8ecea235c7e",
|
|
97
|
+
"executablePath": "chrome-win64/chrome.exe"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type PlatformId } from './platform.js';
|
|
2
|
+
export interface ServerPlatformRelease {
|
|
3
|
+
readonly packageName: string;
|
|
4
|
+
readonly packageVersion: string;
|
|
5
|
+
readonly target: string;
|
|
6
|
+
readonly asset: string;
|
|
7
|
+
readonly executablePath: string;
|
|
8
|
+
readonly sha256: string | null;
|
|
9
|
+
readonly size: number | null;
|
|
10
|
+
readonly minimumGlibc: string | null;
|
|
11
|
+
readonly development: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ServerRelease {
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly protocolVersion: string;
|
|
16
|
+
readonly platforms: Readonly<Record<PlatformId, ServerPlatformRelease>>;
|
|
17
|
+
}
|
|
18
|
+
export interface ChromePlatformRelease {
|
|
19
|
+
readonly platform: 'linux' | 'linux_arm' | 'mac' | 'mac_arm' | 'win64';
|
|
20
|
+
readonly url: string;
|
|
21
|
+
readonly sha256: string;
|
|
22
|
+
readonly executablePath: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ChromeRelease {
|
|
25
|
+
readonly buildId: string;
|
|
26
|
+
readonly platforms: Readonly<Record<PlatformId, ChromePlatformRelease>>;
|
|
27
|
+
}
|
|
28
|
+
export interface ReleaseManifest {
|
|
29
|
+
readonly schemaVersion: 1;
|
|
30
|
+
readonly sdkVersion: string;
|
|
31
|
+
readonly installerVersion: string;
|
|
32
|
+
readonly server: ServerRelease;
|
|
33
|
+
readonly chrome: ChromeRelease;
|
|
34
|
+
}
|
|
35
|
+
export declare function validateReleaseManifest(value: unknown): ReleaseManifest;
|
|
36
|
+
export declare const releaseManifest: ReleaseManifest;
|
package/dist/release.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { protocolVersion } from './generated/protocol.js';
|
|
3
|
+
import { InstallationError } from './install-errors.js';
|
|
4
|
+
import { platformIds } from './platform.js';
|
|
5
|
+
const mappings = {
|
|
6
|
+
'linux-x64-gnu': ['x86_64-unknown-linux-gnu', 'eoka-server-linux-amd64', 'linux', 'linux64'],
|
|
7
|
+
'linux-arm64-gnu': ['aarch64-unknown-linux-gnu', 'eoka-server-linux-arm64', 'linux_arm', 'linux-arm64'],
|
|
8
|
+
'darwin-x64': ['x86_64-apple-darwin', 'eoka-server-darwin-amd64', 'mac', 'mac-x64'],
|
|
9
|
+
'darwin-arm64': ['aarch64-apple-darwin', 'eoka-server-darwin-arm64', 'mac_arm', 'mac-arm64'],
|
|
10
|
+
'win32-x64': ['x86_64-pc-windows-msvc', 'eoka-server-windows-amd64.exe', 'win64', 'win64'],
|
|
11
|
+
};
|
|
12
|
+
function object(value) {
|
|
13
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
14
|
+
throw new Error('Expected release metadata object');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
const digestPattern = /^[a-f0-9]{64}$/;
|
|
18
|
+
const versionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?![\s\S])/;
|
|
19
|
+
function exactNpmVersion(value) {
|
|
20
|
+
if (typeof value !== 'string' || value.length > 256)
|
|
21
|
+
return false;
|
|
22
|
+
const match = versionPattern.exec(value);
|
|
23
|
+
return match !== null && Number.isSafeInteger(Number(match[1])) && Number.isSafeInteger(Number(match[2])) && Number.isSafeInteger(Number(match[3]));
|
|
24
|
+
}
|
|
25
|
+
export function validateReleaseManifest(value) {
|
|
26
|
+
try {
|
|
27
|
+
const manifest = object(value);
|
|
28
|
+
const server = object(manifest.server);
|
|
29
|
+
const chrome = object(manifest.chrome);
|
|
30
|
+
const servers = object(server.platforms);
|
|
31
|
+
const browsers = object(chrome.platforms);
|
|
32
|
+
if (manifest.schemaVersion !== 1 || !exactNpmVersion(manifest.sdkVersion) || manifest.installerVersion !== '3.2.4' || server.version !== '0.5.0' || server.protocolVersion !== `${protocolVersion.major}.${protocolVersion.minor}` || chrome.buildId !== '155.0.8059.39')
|
|
33
|
+
throw new Error('Incompatible release versions');
|
|
34
|
+
if (Object.keys(servers).length !== platformIds.length || Object.keys(browsers).length !== platformIds.length)
|
|
35
|
+
throw new Error('Incomplete platform mapping');
|
|
36
|
+
for (const id of platformIds) {
|
|
37
|
+
const pin = object(servers[id]);
|
|
38
|
+
const browser = object(browsers[id]);
|
|
39
|
+
const [target, asset, installerPlatform, chromePlatform] = mappings[id];
|
|
40
|
+
if (pin.packageName !== `@cbxss/eoka-server-${id}` || pin.packageVersion !== manifest.sdkVersion || pin.target !== target || pin.asset !== asset || pin.executablePath !== (id === 'win32-x64' ? 'bin/eoka-server.exe' : 'bin/eoka-server'))
|
|
41
|
+
throw new Error(`Invalid server mapping: ${id}`);
|
|
42
|
+
if (!((pin.sha256 === null && pin.size === null) || (typeof pin.sha256 === 'string' && digestPattern.test(pin.sha256) && Number.isSafeInteger(pin.size) && pin.size > 0)))
|
|
43
|
+
throw new Error(`Invalid server integrity pin: ${id}`);
|
|
44
|
+
if (typeof pin.development !== 'boolean' || (id.startsWith('linux-') ? typeof pin.minimumGlibc !== 'string' || !/^\d+\.\d+$/.test(pin.minimumGlibc) : pin.minimumGlibc !== null))
|
|
45
|
+
throw new Error(`Invalid server ABI metadata: ${id}`);
|
|
46
|
+
if (!pin.development && id.startsWith('linux-') && pin.minimumGlibc !== '2.35')
|
|
47
|
+
throw new Error(`Invalid release glibc baseline: ${id}`);
|
|
48
|
+
const expectedUrl = `https://storage.googleapis.com/chrome-for-testing-public/${chrome.buildId}/${chromePlatform}/chrome-${chromePlatform}.zip`;
|
|
49
|
+
const expectedExecutable = id.startsWith('darwin-') ? `chrome-${chromePlatform}/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing` : `chrome-${chromePlatform}/chrome${id === 'win32-x64' ? '.exe' : ''}`;
|
|
50
|
+
if (browser.platform !== installerPlatform || browser.url !== expectedUrl || typeof browser.sha256 !== 'string' || !digestPattern.test(browser.sha256) || browser.executablePath !== expectedExecutable)
|
|
51
|
+
throw new Error(`Invalid Chrome pin: ${id}`);
|
|
52
|
+
}
|
|
53
|
+
return freeze(value);
|
|
54
|
+
}
|
|
55
|
+
catch (cause) {
|
|
56
|
+
throw new InstallationError('ReleaseNotPrepared', 'The SDK release manifest is malformed or incompatible. Reinstall a prepared SDK release.', { cause });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function freeze(value) {
|
|
60
|
+
if (value !== null && typeof value === 'object') {
|
|
61
|
+
for (const child of Object.values(value))
|
|
62
|
+
freeze(child);
|
|
63
|
+
Object.freeze(value);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
export const releaseManifest = (() => {
|
|
68
|
+
try {
|
|
69
|
+
return validateReleaseManifest(JSON.parse(readFileSync(new URL('./release-manifest.json', import.meta.url), 'utf8')));
|
|
70
|
+
}
|
|
71
|
+
catch (cause) {
|
|
72
|
+
if (cause instanceof InstallationError)
|
|
73
|
+
throw cause;
|
|
74
|
+
throw new InstallationError('ReleaseNotPrepared', 'The SDK release manifest cannot be read. Reinstall a prepared SDK release.', { cause });
|
|
75
|
+
}
|
|
76
|
+
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ServerBinaryOptions {
|
|
2
|
+
serverPath?: string;
|
|
3
|
+
env?: NodeJS.ProcessEnv;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
export interface ServerBinaryResolution {
|
|
7
|
+
executablePath: string;
|
|
8
|
+
source: 'explicit' | 'environment' | 'package';
|
|
9
|
+
expectedServerVersion?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveServerBinary(options?: ServerBinaryOptions): Promise<ServerBinaryResolution>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants, createReadStream } from 'node:fs';
|
|
3
|
+
import { access, lstat, readFile, realpath, stat } from 'node:fs/promises';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { ConfigurationError } from './errors.js';
|
|
7
|
+
import { InstallationError } from './install-errors.js';
|
|
8
|
+
import { detectPlatform } from './platform.js';
|
|
9
|
+
import { releaseManifest } from './release.js';
|
|
10
|
+
function checkAbort(signal) {
|
|
11
|
+
if (signal?.aborted)
|
|
12
|
+
throw new InstallationError('InstallationAborted', 'Server resolution was aborted.', { cause: signal.reason });
|
|
13
|
+
}
|
|
14
|
+
function isSingleton(value, expected) {
|
|
15
|
+
return Array.isArray(value) && value.length === 1 && value[0] === expected;
|
|
16
|
+
}
|
|
17
|
+
export async function resolveServerBinary(options = {}) {
|
|
18
|
+
const { signal } = options;
|
|
19
|
+
checkAbort(signal);
|
|
20
|
+
const env = options.env ?? process.env;
|
|
21
|
+
const override = options.serverPath ?? env.EOKA_SERVER_BIN;
|
|
22
|
+
if (override !== undefined) {
|
|
23
|
+
if (typeof override !== 'string' || override.trim() === '' || override.includes('\0'))
|
|
24
|
+
throw new ConfigurationError('serverPath or EOKA_SERVER_BIN must be a nonempty filesystem path');
|
|
25
|
+
const executablePath = resolve(override);
|
|
26
|
+
try {
|
|
27
|
+
if (!(await stat(executablePath)).isFile())
|
|
28
|
+
throw new Error('not a regular file');
|
|
29
|
+
await access(executablePath, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
30
|
+
}
|
|
31
|
+
catch (cause) {
|
|
32
|
+
throw new ConfigurationError(`serverPath is not an accessible executable: ${executablePath}`, { cause });
|
|
33
|
+
}
|
|
34
|
+
checkAbort(signal);
|
|
35
|
+
return { executablePath, source: options.serverPath === undefined ? 'environment' : 'explicit' };
|
|
36
|
+
}
|
|
37
|
+
const platform = detectPlatform();
|
|
38
|
+
const pin = releaseManifest.server.platforms[platform];
|
|
39
|
+
let packagePath;
|
|
40
|
+
try {
|
|
41
|
+
packagePath = createRequire(import.meta.url).resolve(`${pin.packageName}/package.json`);
|
|
42
|
+
}
|
|
43
|
+
catch (cause) {
|
|
44
|
+
throw new InstallationError('ServerPackageMissing', `The exact optional dependency ${pin.packageName}@${pin.packageVersion} is missing. Reinstall @cbxss/eoka with optional dependencies enabled (do not use --omit=optional), or install that exact platform package. There is no Cargo, PATH or network fallback.`, { cause });
|
|
45
|
+
}
|
|
46
|
+
if (pin.sha256 === null || pin.size === null)
|
|
47
|
+
throw new InstallationError('ReleaseNotPrepared', `The SDK has no staged server integrity pin for ${platform}. Use a prepared SDK plus its matching platform package, or set serverPath explicitly.`);
|
|
48
|
+
if (pin.minimumGlibc !== null && pin.minimumGlibc !== '2.35') {
|
|
49
|
+
const report = process.report.getReport();
|
|
50
|
+
const current = report.header.glibcVersionRuntime?.split('.').map(Number);
|
|
51
|
+
const minimum = pin.minimumGlibc.split('.').map(Number);
|
|
52
|
+
if (!current || current[0] < minimum[0] || (current[0] === minimum[0] && current[1] < minimum[1]))
|
|
53
|
+
throw new InstallationError('UnsupportedPlatform', `This ${pin.development ? 'host-development' : 'release'} server requires glibc >= ${pin.minimumGlibc}. The SDK never substitutes another binary.`);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const packageRoot = await realpath(dirname(packagePath));
|
|
57
|
+
const packageMetadata = JSON.parse(await readFile(packagePath, { encoding: 'utf8', ...(signal === undefined ? {} : { signal }) }));
|
|
58
|
+
const [os, arch] = platform.split('-');
|
|
59
|
+
if (packageMetadata.name !== pin.packageName || packageMetadata.version !== pin.packageVersion || !isSingleton(packageMetadata.os, os) || !isSingleton(packageMetadata.cpu, arch) || (os === 'linux' && !isSingleton(packageMetadata.libc, 'glibc')))
|
|
60
|
+
throw new Error('Package name, exact version, OS, architecture or libc does not match the SDK pin');
|
|
61
|
+
const metadataPath = join(packageRoot, 'release-metadata.json');
|
|
62
|
+
if (!(await lstat(metadataPath)).isFile())
|
|
63
|
+
throw new Error('Release metadata must be a regular file, not a symlink');
|
|
64
|
+
const metadata = JSON.parse(await readFile(metadataPath, { encoding: 'utf8', ...(signal === undefined ? {} : { signal }) }));
|
|
65
|
+
const expectedMetadata = {
|
|
66
|
+
schemaVersion: 1, sdkVersion: releaseManifest.sdkVersion, packageName: pin.packageName, packageVersion: pin.packageVersion,
|
|
67
|
+
platform, target: pin.target, serverVersion: releaseManifest.server.version, protocolVersion: releaseManifest.server.protocolVersion,
|
|
68
|
+
minimumGlibc: pin.minimumGlibc, development: pin.development,
|
|
69
|
+
};
|
|
70
|
+
for (const key of Object.keys(expectedMetadata)) {
|
|
71
|
+
if (metadata[key] !== expectedMetadata[key])
|
|
72
|
+
throw new Error(`Release metadata mismatch: ${key}`);
|
|
73
|
+
}
|
|
74
|
+
const binary = metadata.binary;
|
|
75
|
+
if (!binary || binary.path !== pin.executablePath || binary.sha256 !== pin.sha256 || binary.size !== pin.size)
|
|
76
|
+
throw new Error('Binary release metadata does not match the SDK pin');
|
|
77
|
+
const executablePath = join(packageRoot, pin.executablePath);
|
|
78
|
+
let ancestor = dirname(executablePath);
|
|
79
|
+
while (ancestor !== packageRoot) {
|
|
80
|
+
if (!(await lstat(ancestor)).isDirectory())
|
|
81
|
+
throw new Error('Executable parent must be a directory, not a symlink');
|
|
82
|
+
ancestor = dirname(ancestor);
|
|
83
|
+
}
|
|
84
|
+
const file = await lstat(executablePath);
|
|
85
|
+
if (!file.isFile() || file.size !== pin.size || (process.platform !== 'win32' && ((file.mode & 0o111) === 0 || (file.mode & 0o022) !== 0)))
|
|
86
|
+
throw new Error('Binary must be a regular executable with the pinned size and no group/world writable mode');
|
|
87
|
+
const canonical = await realpath(executablePath);
|
|
88
|
+
const contained = relative(packageRoot, canonical);
|
|
89
|
+
if (contained.startsWith(`..${sep}`) || contained === '..' || resolve(packageRoot, contained) !== canonical)
|
|
90
|
+
throw new Error('Binary escapes its platform package');
|
|
91
|
+
await access(executablePath, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
92
|
+
const hash = createHash('sha256');
|
|
93
|
+
const stream = createReadStream(executablePath, signal === undefined ? {} : { signal });
|
|
94
|
+
for await (const chunk of stream)
|
|
95
|
+
hash.update(chunk);
|
|
96
|
+
checkAbort(signal);
|
|
97
|
+
if (hash.digest('hex') !== pin.sha256)
|
|
98
|
+
throw new InstallationError('IntegrityMismatch', `The server binary in ${pin.packageName} does not match the SDK's SHA-256 pin. Reinstall the exact SDK/platform release.`);
|
|
99
|
+
return { executablePath, source: 'package', expectedServerVersion: releaseManifest.server.version };
|
|
100
|
+
}
|
|
101
|
+
catch (cause) {
|
|
102
|
+
checkAbort(signal);
|
|
103
|
+
if (cause instanceof InstallationError)
|
|
104
|
+
throw cause;
|
|
105
|
+
throw new InstallationError('ServerPackageMismatch', `The installed ${pin.packageName}@${pin.packageVersion} does not match this prepared SDK release. Reinstall both exact packages.`, { cause });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type MethodName, type MethodParams, type MethodResults } from './generated/protocol.js';
|
|
2
|
+
import type { CallOptions, InvokeClient } from './client.js';
|
|
3
|
+
export interface SidecarStartOptions {
|
|
4
|
+
serverPath: string;
|
|
5
|
+
env?: NodeJS.ProcessEnv;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
shutdownTimeoutMs?: number;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
redactionValues?: readonly string[];
|
|
10
|
+
onTransport?: (transport: SidecarTransport) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface TrackedInvocation<M extends MethodName> {
|
|
13
|
+
result: Promise<MethodResults[M]>;
|
|
14
|
+
completion: Promise<MethodResults[M]>;
|
|
15
|
+
}
|
|
16
|
+
export declare class SidecarTransport implements InvokeClient {
|
|
17
|
+
private readonly child;
|
|
18
|
+
private readonly shutdownTimeoutMs;
|
|
19
|
+
private readonly pending;
|
|
20
|
+
private readonly decoder;
|
|
21
|
+
private greeting;
|
|
22
|
+
private supported;
|
|
23
|
+
private nextId;
|
|
24
|
+
private messageLimit;
|
|
25
|
+
private pendingLimit;
|
|
26
|
+
private frame;
|
|
27
|
+
private frameLength;
|
|
28
|
+
private queuedBytes;
|
|
29
|
+
private blocked;
|
|
30
|
+
private closing;
|
|
31
|
+
private quiescing;
|
|
32
|
+
private finished;
|
|
33
|
+
private exited;
|
|
34
|
+
private stderrBytes;
|
|
35
|
+
private stderrClipped;
|
|
36
|
+
private finalStderr;
|
|
37
|
+
private readonly secrets;
|
|
38
|
+
private escalating;
|
|
39
|
+
private failure;
|
|
40
|
+
private cleanupError;
|
|
41
|
+
private closeCompletion;
|
|
42
|
+
private teardownTimer;
|
|
43
|
+
private shutdownId;
|
|
44
|
+
private readonly closed;
|
|
45
|
+
private terminationConfirmed;
|
|
46
|
+
private shutdownAcknowledged;
|
|
47
|
+
private childClosed;
|
|
48
|
+
private windowsTreeTerminated;
|
|
49
|
+
private constructor();
|
|
50
|
+
static start(options: SidecarStartOptions): Promise<SidecarTransport>;
|
|
51
|
+
get hello(): MethodResults['server.hello'];
|
|
52
|
+
get pid(): number | undefined;
|
|
53
|
+
private get stderr();
|
|
54
|
+
supports(method: string): boolean;
|
|
55
|
+
hasCapability(name: string): boolean;
|
|
56
|
+
invoke<M extends MethodName>(method: M, params: MethodParams[M], options?: CallOptions): Promise<MethodResults[M]>;
|
|
57
|
+
invokeTracked<M extends MethodName>(method: M, params: MethodParams[M], options?: CallOptions): TrackedInvocation<M>;
|
|
58
|
+
quiesce(): void;
|
|
59
|
+
invokeCleanup(method: 'browser.close_tab', params: MethodParams['browser.close_tab'], options?: {
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
}): Promise<MethodResults['browser.close_tab']>;
|
|
62
|
+
private validate;
|
|
63
|
+
private request;
|
|
64
|
+
private details;
|
|
65
|
+
private detach;
|
|
66
|
+
private remove;
|
|
67
|
+
private cancel;
|
|
68
|
+
private flush;
|
|
69
|
+
private readonly onDrain;
|
|
70
|
+
private readonly onStderr;
|
|
71
|
+
private readonly onData;
|
|
72
|
+
private response;
|
|
73
|
+
private rejectPending;
|
|
74
|
+
private fail;
|
|
75
|
+
private readonly onEnd;
|
|
76
|
+
private readonly onStreamError;
|
|
77
|
+
private readonly onProcessError;
|
|
78
|
+
private readonly onExit;
|
|
79
|
+
private readonly onClose;
|
|
80
|
+
close(): Promise<void>;
|
|
81
|
+
whenClosed(): Promise<void>;
|
|
82
|
+
get ownedProcessesTerminated(): boolean;
|
|
83
|
+
private beginClose;
|
|
84
|
+
private ownedGroupAlive;
|
|
85
|
+
private signalOwnedTree;
|
|
86
|
+
private terminate;
|
|
87
|
+
private forceOwnedTree;
|
|
88
|
+
private finishClose;
|
|
89
|
+
}
|