@ai-ecoverse/slicc-shared-web 2.14.4 → 2.15.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
@@ -332,6 +332,7 @@ test('boots', async (t) => {
332
332
  | `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 |
333
333
  | `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` |
334
334
  | `headless` | Run Chrome headless | `true` unless `CI` is set; `SLICC_HEADLESS=1` or `0` overrides |
335
+ | `nice` | Lower Chrome's CPU priority to nice 10 (or keep the test process's, if that is lower still) right after it starts, so its helpers and every renderer it starts later inherit it, and a suite that runs several files side by side leaves a developer machine responsive | `true` unless `CI` is set; `SLICC_NICE=1` or `0` overrides |
335
336
  | `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` |
336
337
  | `executable` | The Chromium binary. Without it, `$CHROME_PATH`, then slicc-cdp's `findBrowser()`, then playwright-core (see above) | found |
337
338
  | `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
@@ -391,8 +392,8 @@ A lane that can't have it opts out explicitly, in one of two ways:
391
392
 
392
393
  `close()` stops Chrome and removes its profile. It asks Chrome to close, waits up to 10 s for the exit, sends `SIGKILL`, waits up to 5 s more and then moves on with a warning, so a browser that ignores `Browser.close` or a missed exit never hangs teardown. A test process that ends without `close()` still leaves nothing running:
393
394
  - on `exit` and on `SIGINT`, `SIGTERM` or `SIGHUP`, the harness kills every browser it started in that process, with all its helper processes (Chrome runs in its own process group), with `SIGKILL` and removes its profile and crash dump directory, then re-raises the signal so the process ends the way it would have;
394
- - when the test process dies of `SIGKILL`, no handler runs. A watchdog, a `sh` in its own process group that reads a pipe from the test process, then gets end of file and kills Chrome's process group with `SIGKILL` at once. Chrome also shuts itself down when the CDP pipe closes, but that can take seconds. Only the profile stays behind;
395
- - the first `launch()` in a process removes every `slicc-harness-*` directory in `$TMPDIR` that is older than a day, or older than a minute and no running process uses as its `--user-data-dir`. It never kills a process.
395
+ - when the test process dies of `SIGKILL`, no handler runs. A watchdog, a `sh` in its own process group that reads a pipe from the test process, then gets end of file and kills Chrome's process group with `SIGKILL` at once. Chrome also shuts itself down when the CDP pipe closes, but that can take seconds. Only the profile and the crash dump directory stay behind;
396
+ - the first `launch()` in a process removes every `slicc-harness-*` directory in `$TMPDIR` that is older than a day, or older than a minute and no running process uses as its `--user-data-dir`, and every `slicc-crashes-*` crash dump directory that is older than a day, or older than a minute and no running process (crashpad's `--database`) names. It never kills a process.
396
397
 
397
398
  ## Crash dumps
398
399
 
@@ -1,7 +1,7 @@
1
1
  import { execFile, spawn } from 'node:child_process';
2
2
  import { rmSync } from 'node:fs';
3
3
  import { lstat, mkdir, mkdtemp, readdir, rm, writeFile } from 'node:fs/promises';
4
- import { tmpdir } from 'node:os';
4
+ import { getPriority, setPriority, tmpdir } from 'node:os';
5
5
  import { basename, join } from 'node:path';
6
6
  import { env as inherited } from 'node:process';
7
7
  import { promisify } from 'node:util';
@@ -9,7 +9,7 @@ import { executablePath, explicit } from './browser.mjs';
9
9
  import { cdn } from './cdn.mjs';
10
10
  import { CRASHED, connect, pipe, SEND_TIMEOUT } from './cdp.mjs';
11
11
  import { screenFor } from './display.mjs';
12
- import { crashpad } from './dumps.mjs';
12
+ import { crashpad, DUMPS } from './dumps.mjs';
13
13
  import {
14
14
  builtinWanted,
15
15
  exclusive,
@@ -53,6 +53,23 @@ export function headlessByDefault(env = inherited) {
53
53
  return !env.CI || env.CI === 'false' || env.CI === '0';
54
54
  }
55
55
 
56
+ export const NICE = 10;
57
+
58
+ export function niceByDefault(env = inherited) {
59
+ if (env.SLICC_NICE === '1') return true;
60
+ if (env.SLICC_NICE === '0') return false;
61
+ return !env.CI || env.CI === 'false' || env.CI === '0';
62
+ }
63
+
64
+ export function lower(pid, nice = NICE) {
65
+ try {
66
+ setPriority(pid, Math.max(getPriority(pid), nice));
67
+ return true;
68
+ } catch {
69
+ return false;
70
+ }
71
+ }
72
+
56
73
  export const modeFlags = (headless) =>
57
74
  headless ? ['--headless=new'] : ['--enable-unsafe-swiftshader'];
58
75
 
@@ -106,7 +123,8 @@ export async function start(
106
123
  profile,
107
124
  args = commandLine(profile),
108
125
  executable = undefined,
109
- env = inherited
126
+ env = inherited,
127
+ nice = false
110
128
  ) {
111
129
  const path = executable ?? (await executablePath({ env }));
112
130
  const child = spawn(path, args, {
@@ -114,6 +132,7 @@ export async function start(
114
132
  detached: true,
115
133
  stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'],
116
134
  });
135
+ if (nice && child.pid > 0) lower(child.pid);
117
136
  const stderr = lines(child.stderr);
118
137
  const drained = new Promise((resolve) => child.stderr.once('close', resolve));
119
138
  const exited = new Promise((resolve) => {
@@ -239,16 +258,18 @@ export async function commandLines() {
239
258
  export async function prune(dir = tmpdir(), grace = GRACE) {
240
259
  const lines = await commandLines().catch(ignore);
241
260
  const used = (path) => lines.some((line) => line.includes(`--user-data-dir=${path} `));
261
+ const held = (name) => lines.some((line) => line.includes(`${name} `));
262
+ const busy = (name, path) => (name.startsWith(PREFIX) ? used(path) : held(name));
242
263
  const names = await readdir(dir).catch(() => []);
243
264
  const now = Date.now();
244
265
  const removing = names
245
- .filter((name) => name.startsWith(PREFIX))
266
+ .filter((name) => name.startsWith(PREFIX) || name.startsWith(DUMPS))
246
267
  .map(async (name) => {
247
268
  const path = join(dir, name);
248
269
  const info = await lstat(path).catch(ignore);
249
270
  if (!info?.isDirectory()) return;
250
271
  const age = now - info.mtimeMs;
251
- const orphaned = lines !== null && age > grace && !used(path);
272
+ const orphaned = lines !== null && age > grace && !busy(name, path);
252
273
  if (age > DAY || orphaned) await rm(path, { recursive: true, force: true }).catch(ignore);
253
274
  });
254
275
  await Promise.all(removing);
@@ -332,6 +353,7 @@ export async function launch({
332
353
  profile = inherited.SLICC_PROFILE === '1',
333
354
  realistic = false,
334
355
  headless = headlessByDefault(),
356
+ nice = niceByDefault(),
335
357
  persistent = false,
336
358
  executable,
337
359
  } = {}) {
@@ -354,7 +376,8 @@ export async function launch({
354
376
  userData,
355
377
  commandLine(userData, loaded, args, realistic, builtin, headless),
356
378
  browser,
357
- screen.env
379
+ screen.env,
380
+ nice
358
381
  ).catch((error) => scrap(error, screen.close));
359
382
  const untrack = track(child, [userData, dumps.dir], [screen.child].filter(Boolean));
360
383
  const cdp = await connect(pipe(child.stdio[3], child.stdio[4]), {
package/harness/dumps.mjs CHANGED
@@ -5,13 +5,14 @@ import { env } from 'node:process';
5
5
  import { sleep } from './util.mjs';
6
6
 
7
7
  export const DUMP_WAIT = 10000;
8
+ export const DUMPS = 'slicc-crashes-';
8
9
 
9
10
  async function list(dir, sub) {
10
11
  return (await readdir(join(dir, sub)).catch(() => [])).map((file) => join(sub, file));
11
12
  }
12
13
 
13
14
  export async function crashpad() {
14
- const dir = await mkdtemp(join(tmpdir(), 'slicc-crashes-'));
15
+ const dir = await mkdtemp(join(tmpdir(), DUMPS));
15
16
  const kept = new Set();
16
17
  const scan = async () => {
17
18
  const [pending, completed, writing] = await Promise.all(
package/harness/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  export { connect } from './cdp.mjs';
2
- export { headlessByDefault, launch, modeFlags } from './chrome.mjs';
2
+ export { headlessByDefault, launch, modeFlags, niceByDefault } from './chrome.mjs';
3
3
  export { screenFor } from './display.mjs';
4
4
  export {
5
5
  BUILTIN_ID as EXTENSION_ID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "2.14.4",
3
+ "version": "2.15.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",
@@ -75,12 +75,12 @@
75
75
  "release": "semantic-release"
76
76
  },
77
77
  "devDependencies": {
78
- "@ai-ecoverse/slicc-browsers": "1.24.0",
79
- "@ai-ecoverse/slicc-cdp": "1.50.1",
78
+ "@ai-ecoverse/slicc-browsers": "1.26.5",
79
+ "@ai-ecoverse/slicc-cdp": "1.52.4",
80
80
  "@biomejs/biome": "2.6.6",
81
81
  "lefthook": "2.2.2",
82
- "monocart-coverage-reports": "3.2.0",
83
- "pnpm": "12.18.0",
82
+ "monocart-coverage-reports": "3.2.1",
83
+ "pnpm": "12.19.0",
84
84
  "semantic-release": "25.0.9"
85
85
  },
86
86
  "peerDependencies": {