@ai-ecoverse/slicc-shared-web 2.0.2 → 2.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/README.md CHANGED
@@ -225,7 +225,7 @@ SLICC_UNIT_ALL=1 git commit
225
225
 
226
226
  ## Integration-test harness
227
227
 
228
- `harness/` drives Chromium over raw CDP on `--remote-debugging-pipe`, as its only client, from `node --test`. Chrome runs headed, since headless Chrome behaves slightly differently, so on Linux it needs a display: the pipeline starts Xvfb when the runner has none, and elsewhere `xvfb-run -a npm test` 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`.
228
+ `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, and a headed run on Linux without a display needs `xvfb-run -a`. 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`.
229
229
 
230
230
  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.
231
231
 
@@ -264,13 +264,14 @@ test('boots', async (t) => {
264
264
  | `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 |
265
265
  | `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 |
266
266
  | `extension` | Load the [harness extension](#harness-extension). `false`, or `SLICC_HARNESS_EXTENSION=0` in the environment, leaves it out; any other value of either is an error | `true` |
267
+ | `headless` | Run Chrome headless | `true` unless `CI` is set; `SLICC_HEADLESS=1` or `0` overrides |
267
268
  | `persistent` | Run every test in the default browser context, on the launch's on-disk `slicc-harness-*` profile, instead of a fresh off-the-record context per test. Off-the-record contexts keep OPFS in memory, with a far smaller real budget than `navigator.storage.estimate()` reports, so a suite that stores hundreds of MB there needs this. When a test ends, its tabs are closed and `Storage.clearDataForOrigin` (`storageTypes: 'all'`) clears the server's origin, every origin a page in the context showed (popups the app opened included) and every origin the harness's tabs got a response from, so nothing leaks into the next test. If clearing fails, the test fails | `false` |
268
269
  | `executable` | The Chromium binary. Without it, `$CHROME_PATH`, then slicc-cdp's `findBrowser()`, then playwright-core (see above) | found |
269
270
  | `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
270
271
  | `timeout` | How long `page.until` polls and `page.evaluate` waits, in ms | `30000` |
271
272
  | `stallAfter` | How long one evaluation may run before the harness probes the test's targets, in ms | `30000` |
272
273
  | `profile` | Record a CPU profile of every target, sampled every 100 µs | `true` if `SLICC_PROFILE=1`, else `false` |
273
- | `realistic` | Run Chrome as a user would: without `--disable-background-timer-throttling`, `--disable-backgrounding-occluded-windows` and `--disable-renderer-backgrounding`, so a tab behind another one is hidden and throttled. For measuring background tabs | `false` |
274
+ | `realistic` | Run Chrome as a user would: headed, whatever `headless` says, and without `--disable-background-timer-throttling`, `--disable-backgrounding-occluded-windows` and `--disable-renderer-backgrounding`, so a tab behind another one is hidden and throttled. For measuring background tabs | `false` |
274
275
 
275
276
  `chrome.page(t)` opens a tab and returns the page API: `goto(path)`, `reload()`, `evaluate(fn, ...args)`, `until(fn, ...args)`, `press(key, ...modifiers)` (a key name like `Enter` or `F5`, or a single character typed with its US-layout key code), `type(text)`, `insert(text)`, `enter()`, `init(fn)` (runs in every new document), `expose(name, handler)` (a binding the page calls with a JSON string), `screenshot(file)`, `tab()` (another tab in the same context), `close()`, `send(method, params, ms)` (a raw CDP call in the tab's session), `errors`, `responses` and `dir` (the test's artifact directory). `chrome.pid` is the browser's process id and `chrome.profile` its `slicc-harness-*` profile directory in `$TMPDIR`. `goto` and `reload` wait until the new document is complete and no longer `about:blank`, and retry the navigation once if that never happens. `until` polls until the function returns a truthy value (not only strict `true`) and resolves with that value; the timeout error names the last result. `within(ms, fn, ...args)` is `until` with its own deadline, for a stage that should take a known time. `run(fn, ...args)` or `run(options, fn, ...args)` is for a job that may outlast the `timeout`: it starts `fn` in the page without holding a `Runtime.evaluate` open, then polls it every `everyMs` (1 s) with short evaluates, and resolves or rejects with the job's own result. It decides slow from hung by progress, not by the clock. Progress is a change in `marker` (a function run in the page at each poll, such as `() => window.done`) or in what `progress` returns (an async function run in Node, such as a probe of a process tree's CPU time). With either one set, a job whose progress stays the same for `quietMs` (60 s) fails with `<label>: no progress for N s after M s`, the last marker and progress values, and the page's pending requests and navigations. `maxMs` (30 min) is the outer bound for a job that keeps moving but never ends. Without a `marker` or `progress` only `maxMs` applies. `label` defaults to the start of `fn`'s source. The job's value must survive `returnByValue`, as with `evaluate`. Both stop at the deadline even if one evaluation never answers. Every CDP call has a deadline: `connect(url).send(method, params, sessionId, ms)` rejects with `<method>: no answer in <ms> ms` (60 s unless given), so a stuck page fails its test instead of hanging the run. A crash fails it at once instead:
276
277
  - when the browser dies, every pending and later call rejects with `<method>: browser exited with <signal>` (or `with code <n>`);
@@ -44,12 +44,19 @@ export const unrealistic = [
44
44
  '--disable-renderer-backgrounding',
45
45
  ];
46
46
 
47
+ export function headlessByDefault(env = inherited) {
48
+ if (env.SLICC_HEADLESS === '1') return true;
49
+ if (env.SLICC_HEADLESS === '0') return false;
50
+ return !env.CI || env.CI === 'false' || env.CI === '0';
51
+ }
52
+
47
53
  export function commandLine(
48
54
  profile,
49
55
  extensions = [],
50
56
  extra = [],
51
57
  realistic = false,
52
- builtin = false
58
+ builtin = false,
59
+ headless = headlessByDefault()
53
60
  ) {
54
61
  const loaded = builtin || extensions.length > 0;
55
62
  const dropped = new Set([
@@ -58,7 +65,8 @@ export function commandLine(
58
65
  ]);
59
66
  const base = flags.filter((flag) => !dropped.has(flag));
60
67
  const load = loaded ? ['--enable-unsafe-extension-debugging'] : [];
61
- return [...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
68
+ const mode = headless && !realistic ? ['--headless=new'] : [];
69
+ return [...mode, ...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
62
70
  }
63
71
 
64
72
  export const KEPT = 200;
@@ -310,6 +318,7 @@ export async function launch({
310
318
  stallAfter,
311
319
  profile = inherited.SLICC_PROFILE === '1',
312
320
  realistic = false,
321
+ headless = headlessByDefault(),
313
322
  persistent = false,
314
323
  executable,
315
324
  } = {}) {
@@ -327,7 +336,7 @@ export async function launch({
327
336
  const dumps = await crashpad();
328
337
  const { child, exited, stderr } = await start(
329
338
  userData,
330
- commandLine(userData, loaded, args, realistic, builtin),
339
+ commandLine(userData, loaded, args, realistic, builtin, headless),
331
340
  browser,
332
341
  dumps.env
333
342
  ).catch(async (error) => {
@@ -215,6 +215,12 @@ export function commands({ type, url }, { coverage = ['/'], exits = new Map(), p
215
215
  return list;
216
216
  }
217
217
 
218
+ function destination(run, target, early) {
219
+ if (!run) return target && early;
220
+ const same = run.context === undefined || target?.browserContextId === run.context;
221
+ return same && target && run.console;
222
+ }
223
+
218
224
  export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), profiling } = {}) {
219
225
  const collecting = coverage.length > 0;
220
226
  const watching = collecting || Boolean(profiling);
@@ -277,7 +283,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
277
283
 
278
284
  function log(sessionId, line) {
279
285
  const target = sessions.get(sessionId);
280
- const into = run ? target?.browserContextId === run.context && run.console : target && early;
286
+ const into = destination(run, target, early);
281
287
  if (into) into.push(`${label(target)}: ${line}`);
282
288
  }
283
289
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "2.0.2",
3
+ "version": "2.1.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",
@@ -62,8 +62,8 @@
62
62
  "release": "semantic-release"
63
63
  },
64
64
  "devDependencies": {
65
- "@ai-ecoverse/slicc-browsers": "1.12.0",
66
- "@ai-ecoverse/slicc-cdp": "1.30.18",
65
+ "@ai-ecoverse/slicc-browsers": "1.13.0",
66
+ "@ai-ecoverse/slicc-cdp": "1.30.19",
67
67
  "@biomejs/biome": "2.5.15",
68
68
  "lefthook": "2.2.2",
69
69
  "monocart-coverage-reports": "2.13.2",