@ai-ecoverse/slicc-shared-web 1.19.0 → 1.20.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/README.md CHANGED
@@ -137,6 +137,8 @@ test('boots', async (t) => {
137
137
  - both errors end with the last five lines of the browser's stderr, and each test keeps up to 200 lines it wrote during the test in `chrome-stderr.log`.
138
138
  - a test that saw a renderer crash, or a browser that died of anything but `SIGKILL`, keeps Chrome's minidump of it as `<id>.dmp` in its artifact directory (see [Crash dumps](#crash-dumps)).
139
139
 
140
+ `chrome.cdp` is the browser's own pipe, the one the harness already drives, with no session of its own: test-only, unguarded access that bypasses everything a product guard would do, and never for product code. `send(method, params, sessionId)` makes a raw call at browser level, or in any session the browser has (the harness's auto-attached ones included); a protocol error rejects with the message and keeps the error object as `error.cdp`. `on(listener)` receives every event the browser sends, as `{ method, params, sessionId }`, until `off(listener)` or the function `on` returned. `waitEvent(method, predicate, ms)` resolves with the next matching event (call it before the action that causes the event); the predicate is optional, a predicate alone works too (`waitEvent(predicate, ms)`), and it rejects after `ms` (10 s unless given). `events` is an append-only array of every event since it was first read. That is the `{ send, waitEvent, events }` client the guard runner of `@ai-ecoverse/slicc-browsers` takes, so `run(set, { client, unguarded: chrome.cdp, … })` gives it the unguarded observer that 14 of its vectors need.
141
+
140
142
  When one evaluation runs past `stallAfter`, the harness probes once, without interrupting the wait:
141
143
  - it adds a `pending` line to `console.log` for every navigation and request of the page that has no answer yet, with its age. A worker's script loads in the worker's own session, so its request is left out. Chrome holds CDP messages to a page while a navigation is waiting for its response, so an evaluation that hangs while the page is idle usually means one of these;
142
144
  - it saves `stall-<n>.png` (a screenshot of the page, if the renderer still answers) in the test's artifact directory;
package/harness/cdp.mjs CHANGED
@@ -116,7 +116,12 @@ export async function connect(url, { exited, tail = () => [] } = {}) {
116
116
  const call = pending.get(message.id);
117
117
  pending.delete(message.id);
118
118
  if (!call) notify(message);
119
- else if (message.error) call.reject(new Error(`${call.method}: ${message.error.message}`));
119
+ else if (message.error)
120
+ call.reject(
121
+ Object.assign(new Error(`${call.method}: ${message.error.message}`), {
122
+ cdp: message.error,
123
+ })
124
+ );
120
125
  else call.resolve(message.result);
121
126
  },
122
127
  async () => die(await Promise.race([exited ?? 'socket closed', grace(2000)]))
@@ -225,6 +225,66 @@ export async function prune(dir = tmpdir(), grace = GRACE) {
225
225
 
226
226
  let pruning = null;
227
227
 
228
+ export const WAIT = 10000;
229
+
230
+ export function unguarded(cdp) {
231
+ const listeners = new Set();
232
+ let events = null;
233
+ cdp.on((message) => {
234
+ if (message.method === undefined) return;
235
+ events?.push(message);
236
+ for (const listener of listeners) {
237
+ try {
238
+ listener(message);
239
+ } catch (error) {
240
+ queueMicrotask(() => {
241
+ throw error;
242
+ });
243
+ }
244
+ }
245
+ });
246
+ const off = (listener) => listeners.delete(listener);
247
+ const on = (listener) => {
248
+ listeners.add(listener);
249
+ return () => off(listener);
250
+ };
251
+ return {
252
+ send: (method, params = {}, sessionId = undefined) => cdp.send(method, params, sessionId),
253
+ on,
254
+ off,
255
+ get events() {
256
+ events ??= [];
257
+ return events;
258
+ },
259
+ waitEvent(match, ...rest) {
260
+ const method = typeof match === 'string' ? match : undefined;
261
+ const named = method && (rest.length > 1 || typeof rest[0] === 'function');
262
+ const [predicate, ms = WAIT] = method ? (named ? rest : [null, ...rest]) : [match, ...rest];
263
+ const wanted = (event) =>
264
+ (!method || event.method === method) && (!predicate || predicate(event));
265
+ return new Promise((resolve, reject) => {
266
+ const timer = setTimeout(() => {
267
+ off(listener);
268
+ reject(new Error(`waitEvent ${method ?? 'predicate'}: no event in ${ms} ms`));
269
+ }, ms);
270
+ const settle = (fn, value) => {
271
+ clearTimeout(timer);
272
+ off(listener);
273
+ fn(value);
274
+ };
275
+ const listener = (event) => {
276
+ try {
277
+ if (wanted(event)) settle(resolve, event);
278
+ } catch (error) {
279
+ settle(reject, error);
280
+ }
281
+ };
282
+ on(listener);
283
+ });
284
+ },
285
+ };
286
+ }
287
+
228
288
  export async function launch({
229
289
  roots,
230
290
  aliases,
@@ -347,6 +407,7 @@ export async function launch({
347
407
  }
348
408
 
349
409
  return {
410
+ cdp: unguarded(cdp),
350
411
  url: server.url,
351
412
  pid: child.pid,
352
413
  profile: userData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -61,6 +61,7 @@
61
61
  "release": "semantic-release"
62
62
  },
63
63
  "devDependencies": {
64
+ "@ai-ecoverse/slicc-browsers": "1.7.0",
64
65
  "@biomejs/biome": "2.5.15",
65
66
  "monocart-coverage-reports": "2.13.2",
66
67
  "playwright-core": "1.64.0",