@ai-ecoverse/slicc-shared-web 2.8.0 → 2.8.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 +2 -2
- package/harness/chrome.mjs +4 -6
- package/harness/recorder.mjs +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -269,7 +269,7 @@ SLICC_UNIT_ALL=1 git commit
|
|
|
269
269
|
|
|
270
270
|
## Integration-test harness
|
|
271
271
|
|
|
272
|
-
`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. 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. 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`.
|
|
272
|
+
`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. 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) only pages start paused: service and shared 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). 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`.
|
|
273
273
|
|
|
274
274
|
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.
|
|
275
275
|
|
|
@@ -303,7 +303,7 @@ test('boots', async (t) => {
|
|
|
303
303
|
| `roots` | `[urlPrefix, directory]` pairs the local server serves, first match wins | `[['/', 'src/']]` |
|
|
304
304
|
| `aliases` | Extra `[urlPrefix, directory]` pairs used only to map coverage and profiles back to files, for scripts that something else serves, such as a service worker | none |
|
|
305
305
|
| `isolated` | Send COOP, COEP and CORP on every response, so pages are cross-origin isolated | `false` |
|
|
306
|
-
| `coverage` | URL prefixes whose `.js`/`.mjs` scripts count for coverage. `node_modules/` never does. A `.map` next to a file is used. `[]` collects nothing: without profiling, no target gets the debugger, the profiler, exit breakpoints or a `beforeunload` pause, and workers
|
|
306
|
+
| `coverage` | URL prefixes whose `.js`/`.mjs` scripts count for coverage. `node_modules/` never does. A `.map` next to a file is used. `[]` collects nothing: without profiling, no target gets the debugger, the profiler, exit breakpoints or a `beforeunload` pause, and no worker, service and shared workers included, waits for the harness to start | `['/']` |
|
|
307
307
|
| `exits` | `{ urlPath: [regex, ...] }`: a breakpoint on the first line matching each pattern in that worker script, where the harness takes the worker's coverage and profile before it closes itself | none |
|
|
308
308
|
| `intercept` | Remote URL prefixes answered from a disk cache in `node_modules/.cache/`. Registry documents (anything on a `registry.*` host but a `/-/….tgz` tarball: packuments, abbreviated or full, and dist-tags) are fetched fresh once per test process and only served from the disk cache when the registry can't be reached (a `4xx` is passed on) | none |
|
|
309
309
|
| `extensions` | Unpacked extension directories to load. They are loaded with `Extensions.loadUnpacked` (behind `--enable-unsafe-extension-debugging`) once the harness is attached, so their service workers start paused like every other target. Their scripts are covered and profiled like the repo's own, and tests then run in the default browser context, closing their tabs when they end, because Chrome does not run extensions in the per-test contexts | none |
|
package/harness/chrome.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
unpacked,
|
|
20
20
|
} from './extensions.mjs';
|
|
21
21
|
import { page } from './page.mjs';
|
|
22
|
-
import { breakpoints, recorder } from './recorder.mjs';
|
|
22
|
+
import { autoAttach, breakpoints, recorder, unpaused } from './recorder.mjs';
|
|
23
23
|
import { serve } from './server.mjs';
|
|
24
24
|
import { artifacts, bounded, ignore, sleep, slug, TIMED_OUT } from './util.mjs';
|
|
25
25
|
|
|
@@ -373,11 +373,9 @@ export async function launch({
|
|
|
373
373
|
});
|
|
374
374
|
const remote = await cdn(cdp, intercept);
|
|
375
375
|
await cdp.send('Target.setDiscoverTargets', { discover: true });
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
flatten: true,
|
|
380
|
-
});
|
|
376
|
+
const attaching = autoAttach({ coverage, profiling: profile });
|
|
377
|
+
if (attaching.filter) cdp.on((event) => unpaused(cdp, event));
|
|
378
|
+
await cdp.send('Target.setAutoAttach', attaching);
|
|
381
379
|
const harnessExtension = await (async () => {
|
|
382
380
|
const own = builtin ? await installBuiltin(cdp) : null;
|
|
383
381
|
await install(cdp, found);
|
package/harness/recorder.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { bounded, ignore, raw, samples, sleep, TIMED_OUT } from './util.mjs';
|
|
|
10
10
|
const Util = mcrUtil.Util ?? mcrUtil.default;
|
|
11
11
|
|
|
12
12
|
const profiled = new Set(['page', 'worker', 'service_worker', 'shared_worker']);
|
|
13
|
+
const unheld = ['service_worker', 'shared_worker'];
|
|
13
14
|
const sampling = [['Profiler.setSamplingInterval', { interval: 100 }], ['Profiler.start']];
|
|
14
15
|
const unloading = 'sliccHarnessUnload';
|
|
15
16
|
const unload = `addEventListener('beforeunload', function ${unloading}() { debugger; })`;
|
|
@@ -176,6 +177,19 @@ export function ownership(parents) {
|
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
export function autoAttach({ coverage = ['/'], profiling } = {}) {
|
|
181
|
+
const attach = { autoAttach: true, waitForDebuggerOnStart: true, flatten: true };
|
|
182
|
+
if (coverage.length > 0 || profiling) return attach;
|
|
183
|
+
const skipped = [...unheld, 'browser', 'tab'].map((type) => ({ type, exclude: true }));
|
|
184
|
+
return { ...attach, filter: [...skipped, {}] };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function unpaused(cdp, { method, params }) {
|
|
188
|
+
if (method !== 'Target.targetCreated' || !unheld.includes(params.targetInfo.type)) return null;
|
|
189
|
+
const { targetId } = params.targetInfo;
|
|
190
|
+
return cdp.send('Target.attachToTarget', { targetId, flatten: true }).catch(ignore);
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
export function retain(scripts, result) {
|
|
180
194
|
for (const script of result) {
|
|
181
195
|
const prev = scripts.get(script.url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.1",
|
|
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.5",
|
|
70
|
-
"@ai-ecoverse/slicc-cdp": "1.
|
|
70
|
+
"@ai-ecoverse/slicc-cdp": "1.31.1",
|
|
71
71
|
"@biomejs/biome": "2.5.15",
|
|
72
72
|
"lefthook": "2.2.2",
|
|
73
73
|
"monocart-coverage-reports": "2.13.2",
|