@ai-ecoverse/slicc-shared-web 2.12.3 → 2.12.4
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 +1 -1
- package/harness/recorder.mjs +7 -7
- package/harness/targets.mjs +59 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -285,7 +285,7 @@ SLICC_UNIT_ALL=1 git commit
|
|
|
285
285
|
|
|
286
286
|
## Integration-test harness
|
|
287
287
|
|
|
288
|
-
`harness/` drives Chromium over raw CDP on `--remote-debugging-pipe`, as its only client, from `node --test`. On CI (`CI` set, as GitHub Actions does) Chrome runs headed, since headless Chrome behaves slightly differently; the pipeline starts Xvfb when the runner has no display. On a developer machine (no `CI`) it runs headless, so a test run doesn't open windows. `SLICC_HEADLESS=1` or `0`, or `launch({ headless })`, overrides either way. On Linux, a headed Chrome on CI (or with no `DISPLAY`) gets an Xvfb display of its own, started with `-displayfd` so it picks a free number and stopped with the browser: browsers launched side by side, as `node --test` runs files with `--test-concurrency`, never share a screen, so none takes another's window focus (four on one display broke `:focus-visible` checks in slicc-spectrum#572). This needs `Xvfb` on `PATH`; without it, Chrome uses `DISPLAY`, and on a Linux desktop without `CI` it always does. A repo that launches its own Chrome, for example on a TCP debugging port that `launch()` doesn't offer, matches this with the same exports: `headlessByDefault(env)` says whether to run headless, `modeFlags(headless)` gives the flags for that mode, and `screenFor(headed, env)` starts the private Xvfb when one is needed and returns `{ env, child, close }`, whose `env` the Chrome process gets. A headed Chrome gets `--enable-unsafe-swiftshader`, so WebGL falls back to software on a display without a GPU, as headless Chrome's does (slicc-bios#901's splash scene saw no WebGL2 otherwise). Every page, service worker, shared worker and dedicated worker, nested ones included, starts paused, gets coverage (and the CPU profiler, when profiling is on) switched on in the same tick, and only then runs. With nothing to collect (`coverage: []` and profiling off) pages and shared workers start paused, and service workers are left out of the auto-attach and attached once they exist, so they never wait for the harness. A held start that Chrome repeats when it stops and restarts a service worker during an update left the updated worker installed and the next navigation unanswered whenever the harness was slow to run it (slicc-bios#844, #836, #789). Shared workers stay in the held auto-attach: attaching one after the fact races its teardown, and Chrome's browser process then crashes on a failed `worker_host_` check in `shared_worker_devtools_agent_host.cc` (slicc-bios#901). Each test gets its own browser context and leaves `artifacts/<suite>/<test>/` behind: a screenshot per tab and a `console.log` of every target. Lines logged before the first test, such as an extension service worker's at startup, go into the first test's `console.log`. The global teardown merges the raw coverage into `coverage/` (console table, lcov, V8 HTML) and writes `artifacts/hotspots.md`.
|
|
288
|
+
`harness/` drives Chromium over raw CDP on `--remote-debugging-pipe`, as its only client, from `node --test`. On CI (`CI` set, as GitHub Actions does) Chrome runs headed, since headless Chrome behaves slightly differently; the pipeline starts Xvfb when the runner has no display. On a developer machine (no `CI`) it runs headless, so a test run doesn't open windows. `SLICC_HEADLESS=1` or `0`, or `launch({ headless })`, overrides either way. On Linux, a headed Chrome on CI (or with no `DISPLAY`) gets an Xvfb display of its own, started with `-displayfd` so it picks a free number and stopped with the browser: browsers launched side by side, as `node --test` runs files with `--test-concurrency`, never share a screen, so none takes another's window focus (four on one display broke `:focus-visible` checks in slicc-spectrum#572). This needs `Xvfb` on `PATH`; without it, Chrome uses `DISPLAY`, and on a Linux desktop without `CI` it always does. A repo that launches its own Chrome, for example on a TCP debugging port that `launch()` doesn't offer, matches this with the same exports: `headlessByDefault(env)` says whether to run headless, `modeFlags(headless)` gives the flags for that mode, and `screenFor(headed, env)` starts the private Xvfb when one is needed and returns `{ env, child, close }`, whose `env` the Chrome process gets. A headed Chrome gets `--enable-unsafe-swiftshader`, so WebGL falls back to software on a display without a GPU, as headless Chrome's does (slicc-bios#901's splash scene saw no WebGL2 otherwise). Every page, service worker, shared worker and dedicated worker, nested ones included, starts paused, gets coverage (and the CPU profiler, when profiling is on) switched on in the same tick, and only then runs. With nothing to collect (`coverage: []` and profiling off) pages and shared workers start paused, and service workers are left out of the auto-attach and attached once they exist, so they never wait for the harness. A held start that Chrome repeats when it stops and restarts a service worker during an update left the updated worker installed and the next navigation unanswered whenever the harness was slow to run it (slicc-bios#844, #836, #789). Shared workers stay in the held auto-attach: attaching one after the fact races its teardown, and Chrome's browser process then crashes on a failed `worker_host_` check in `shared_worker_devtools_agent_host.cc` (slicc-bios#901). Each test gets its own browser context and leaves `artifacts/<suite>/<test>/` behind: a screenshot per tab and a `console.log` of every target. `targets.log` is a timestamped JSON-lines timeline of target discovery, attachment (including parent sessions and held starts), navigation, load events and failed loads. It also records when the harness sends `Runtime.runIfWaitingForDebugger`, whether Chrome answers or the call fails, and any failed attachment-setup commands; each test starts with a snapshot of existing sessions and their last resume state. Lines logged before the first test, such as an extension service worker's at startup, go into the first test's `console.log`. The global teardown merges the raw coverage into `coverage/` (console table, lcov, V8 HTML) and writes `artifacts/hotspots.md`.
|
|
289
289
|
|
|
290
290
|
CPU profiling is off by default. V8's sampler interrupts each page and worker thread every 100 µs with a signal, and the renderer SIGSEGVs in slicc-bios#114 all fault inside a signal handler walking the interrupted thread's frames, which points at it. Turn it on with `profile: true` or `SLICC_PROFILE=1` to get one CPU profile per target and snapshot in the test's artifact directory, and the 15 frames with the most self time in the repo's own scripts in `hotspots.md`. Without it, `hotspots.md` says that profiling is off.
|
|
291
291
|
|
package/harness/recorder.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { cwd } from 'node:process';
|
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import * as mcrUtil from 'monocart-coverage-reports/util';
|
|
6
6
|
import { CRASHED } from './cdp.mjs';
|
|
7
|
+
import { targetLog } from './targets.mjs';
|
|
7
8
|
import { trace } from './trace.mjs';
|
|
8
9
|
import { bounded, ignore, raw, samples, sleep, TIMED_OUT } from './util.mjs';
|
|
9
10
|
|
|
@@ -243,6 +244,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
243
244
|
const parents = new Map();
|
|
244
245
|
const tabs = new Map();
|
|
245
246
|
const early = [];
|
|
247
|
+
const targets = targetLog(cdp);
|
|
246
248
|
const own = ownership(parents);
|
|
247
249
|
const ours = covered(server, coverage);
|
|
248
250
|
let run = null;
|
|
@@ -285,16 +287,12 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
285
287
|
const list = commands(targetInfo, { coverage, exits, profiling });
|
|
286
288
|
if (waitingForDebugger) list.push(['Runtime.runIfWaitingForDebugger']);
|
|
287
289
|
const ready = Promise.all(
|
|
288
|
-
list.map(([method, params]) =>
|
|
290
|
+
list.map(([method, params]) => targets.send(method, params, sessionId))
|
|
289
291
|
);
|
|
290
292
|
if (targetInfo.type === 'page') tab(targetInfo.targetId).resolve(ready.then(() => sessionId));
|
|
291
293
|
return ready;
|
|
292
294
|
}
|
|
293
295
|
|
|
294
|
-
function resume(sessionId) {
|
|
295
|
-
return cdp.send('Runtime.runIfWaitingForDebugger', {}, sessionId).catch(ignore);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
296
|
function log(sessionId, line) {
|
|
299
297
|
const target = sessions.get(sessionId);
|
|
300
298
|
const into = destination(run, target, early);
|
|
@@ -333,7 +331,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
333
331
|
async function lifecycle({ method, params, sessionId }) {
|
|
334
332
|
if (method === 'Target.attachedToTarget') {
|
|
335
333
|
if (own.adopt(params, sessionId)) await attach(params);
|
|
336
|
-
else if (own.ours(params.sessionId)) await resume(params.sessionId);
|
|
334
|
+
else if (own.ours(params.sessionId)) await targets.resume(params.sessionId);
|
|
337
335
|
}
|
|
338
336
|
if (method === 'Target.detachedFromTarget') {
|
|
339
337
|
sessions.delete(params.sessionId);
|
|
@@ -341,7 +339,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
341
339
|
own.drop(params.sessionId);
|
|
342
340
|
}
|
|
343
341
|
const restarted = method === 'Inspector.targetReloadedAfterCrash';
|
|
344
|
-
if (restarted && own.ours(sessionId)) await resume(sessionId);
|
|
342
|
+
if (restarted && own.ours(sessionId)) await targets.resume(sessionId);
|
|
345
343
|
}
|
|
346
344
|
|
|
347
345
|
cdp.on(async ({ method, params, sessionId }) => {
|
|
@@ -378,6 +376,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
378
376
|
}
|
|
379
377
|
|
|
380
378
|
function begin(context, dir, name) {
|
|
379
|
+
targets.begin();
|
|
381
380
|
run = {
|
|
382
381
|
context,
|
|
383
382
|
dir,
|
|
@@ -401,6 +400,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
401
400
|
await mkdir(raw, { recursive: true });
|
|
402
401
|
await mkdir(samples, { recursive: true });
|
|
403
402
|
await Promise.all([
|
|
403
|
+
writeFile(new URL('targets.log', current.dir), targets.text()),
|
|
404
404
|
writeFile(new URL(`${current.name}.json`, raw), JSON.stringify(entries.filter(Boolean))),
|
|
405
405
|
writeFile(new URL(`${current.name}.json`, samples), JSON.stringify(found)),
|
|
406
406
|
writeFile(
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const events = new Set([
|
|
2
|
+
'Target.targetCreated',
|
|
3
|
+
'Target.targetInfoChanged',
|
|
4
|
+
'Target.targetDestroyed',
|
|
5
|
+
'Target.attachedToTarget',
|
|
6
|
+
'Target.detachedFromTarget',
|
|
7
|
+
'Page.windowOpen',
|
|
8
|
+
'Page.frameNavigated',
|
|
9
|
+
'Page.loadEventFired',
|
|
10
|
+
'Network.loadingFailed',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export function targetLog(cdp) {
|
|
14
|
+
const sessions = new Map();
|
|
15
|
+
let lines = [];
|
|
16
|
+
const log = (event) => lines.push(JSON.stringify({ at: new Date().toISOString(), ...event }));
|
|
17
|
+
const resume = (sessionId, state, error) => {
|
|
18
|
+
const result = { at: new Date().toISOString(), state, error: error?.message };
|
|
19
|
+
const attached = sessions.get(sessionId);
|
|
20
|
+
if (attached) attached.resume = result;
|
|
21
|
+
log({ method: 'Runtime.runIfWaitingForDebugger', sessionId, ...result });
|
|
22
|
+
};
|
|
23
|
+
cdp.on(({ method, params, sessionId }) => {
|
|
24
|
+
if (method === 'Target.attachedToTarget') {
|
|
25
|
+
sessions.set(params.sessionId, { ...params, parent: sessionId });
|
|
26
|
+
}
|
|
27
|
+
if (method === 'Target.detachedFromTarget') sessions.delete(params.sessionId);
|
|
28
|
+
if (method === 'Target.targetInfoChanged') {
|
|
29
|
+
for (const attached of sessions.values()) {
|
|
30
|
+
if (attached.targetInfo.targetId === params.targetInfo.targetId) {
|
|
31
|
+
attached.targetInfo = params.targetInfo;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (events.has(method)) log({ method, sessionId, params });
|
|
36
|
+
});
|
|
37
|
+
async function send(method, params, sessionId) {
|
|
38
|
+
const waiting = method === 'Runtime.runIfWaitingForDebugger';
|
|
39
|
+
if (waiting) resume(sessionId, 'sent');
|
|
40
|
+
try {
|
|
41
|
+
const result = await cdp.send(method, params, sessionId);
|
|
42
|
+
if (waiting) resume(sessionId, 'answered');
|
|
43
|
+
return result;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (waiting) resume(sessionId, 'failed', error);
|
|
46
|
+
else log({ method, sessionId, state: 'failed', error: error.message });
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
send,
|
|
52
|
+
resume: (sessionId) => send('Runtime.runIfWaitingForDebugger', {}, sessionId),
|
|
53
|
+
begin() {
|
|
54
|
+
lines = [];
|
|
55
|
+
for (const params of sessions.values()) log({ method: 'Harness.existingSession', params });
|
|
56
|
+
},
|
|
57
|
+
text: () => lines.map((line) => `${line}\n`).join(''),
|
|
58
|
+
};
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.4",
|
|
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",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@ai-ecoverse/slicc-browsers": "1.18.14",
|
|
70
|
-
"@ai-ecoverse/slicc-cdp": "1.41.
|
|
70
|
+
"@ai-ecoverse/slicc-cdp": "1.41.16",
|
|
71
71
|
"@biomejs/biome": "2.5.15",
|
|
72
72
|
"lefthook": "2.2.2",
|
|
73
73
|
"monocart-coverage-reports": "2.13.2",
|