@ai-ecoverse/slicc-shared-web 1.14.0 → 1.15.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 +10 -3
- package/harness/browser.mjs +50 -0
- package/harness/chrome.mjs +14 -5
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Install it from npm, and pin the reusable workflow to the matching `vX.Y.Z` tag.
|
|
|
20
20
|
npm install --save-dev --save-exact @ai-ecoverse/slicc-shared-web
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
The hooks expect two scripts in each repo: `test:unit`, which writes `coverage/unit/lcov.info` (unit tests stay out of git), and, in TypeScript repos, `typecheck`. The reusable workflow expects `lint`, plus `test` for the integration tests, with a `pretest` that installs Chromium (`playwright-core install --no-shell chromium`). Its inputs `lint`, `test`, `chromium` and `node-version` override those, and `timeout-minutes` (20 by default) gives a long job, such as a background-tab measurement, more time. `runs-on` (`ubuntu-latest` by default) picks the runner label, such as a self-hosted pool or one an earlier job chose; the caller decides which runner may run which code, so a fork's pull request should stay on a GitHub-hosted runner. With `chromium` on, Chromium's system libraries are installed with `playwright-core install-deps` only where it runs as root or `sudo -n true` works; on a runner without root (one with "no new privileges", say) the step is skipped with a notice and the image must already ship them. The `pretest` download needs no root either way. The diff-coverage hook runs `diff-cover` through `uvx`, so install [uv](https://docs.astral.sh/uv/) once.
|
|
23
|
+
The hooks expect two scripts in each repo: `test:unit`, which writes `coverage/unit/lcov.info` (unit tests stay out of git), and, in TypeScript repos, `typecheck`. The reusable workflow expects `lint`, plus `test` for the integration tests, with a `pretest` that installs Chromium (`slicc-cdp install-browser --version <x.y.z.w>`, or `playwright-core install --no-shell chromium`). Its inputs `lint`, `test`, `chromium` and `node-version` override those, and `timeout-minutes` (20 by default) gives a long job, such as a background-tab measurement, more time. `runs-on` (`ubuntu-latest` by default) picks the runner label, such as a self-hosted pool or one an earlier job chose; the caller decides which runner may run which code, so a fork's pull request should stay on a GitHub-hosted runner. With `chromium` on, Chromium's system libraries are installed with `playwright-core install-deps` only where it runs as root or `sudo -n true` works; on a runner without root (one with "no new privileges", say) the step is skipped with a notice and the image must already ship them. The `pretest` download needs no root either way. The diff-coverage hook runs `diff-cover` through `uvx`, so install [uv](https://docs.astral.sh/uv/) once.
|
|
24
24
|
|
|
25
25
|
## Rules every repo follows
|
|
26
26
|
|
|
@@ -31,11 +31,17 @@ The hooks expect two scripts in each repo: `test:unit`, which writes `coverage/u
|
|
|
31
31
|
|
|
32
32
|
## Integration-test harness
|
|
33
33
|
|
|
34
|
-
`harness/` drives
|
|
34
|
+
`harness/` drives Chromium over raw CDP on `--remote-debugging-pipe`, as its only client, from `node --test`. 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`.
|
|
35
35
|
|
|
36
36
|
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.
|
|
37
37
|
|
|
38
|
-
`
|
|
38
|
+
`monocart-coverage-reports` is a peer dependency; pin it in the repo's `devDependencies`. The browser is the first of these:
|
|
39
|
+
- `launch({ executable })`;
|
|
40
|
+
- `$CHROME_PATH`;
|
|
41
|
+
- `findBrowser()` from `@ai-ecoverse/slicc-cdp`. It finds a Chrome for Testing that `npx slicc-cdp install-browser --version <x.y.z.w>` installed, or a system Chrome;
|
|
42
|
+
- `chromium.executablePath()` from `playwright-core`, after `npx playwright-core install chromium`.
|
|
43
|
+
|
|
44
|
+
Both packages are optional peers: pin whichever the repo uses. Neither is imported unless the step before it found nothing. Whatever the browser, its profile is a fresh `slicc-harness-*` directory in the temp dir. A repo describes what to serve and launches the browser once per test file:
|
|
39
45
|
|
|
40
46
|
```js
|
|
41
47
|
import { launch } from '@ai-ecoverse/slicc-shared-web/harness';
|
|
@@ -64,6 +70,7 @@ test('boots', async (t) => {
|
|
|
64
70
|
| `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 |
|
|
65
71
|
| `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 |
|
|
66
72
|
| `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` |
|
|
73
|
+
| `executable` | The Chromium binary. Without it, `$CHROME_PATH`, then slicc-cdp's `findBrowser()`, then playwright-core (see above) | found |
|
|
67
74
|
| `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
|
|
68
75
|
| `timeout` | How long `page.until` polls and `page.evaluate` waits, in ms | `30000` |
|
|
69
76
|
| `stallAfter` | How long one evaluation may run before the harness probes the test's targets, in ms | `30000` |
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { env as inherited } from 'node:process';
|
|
3
|
+
|
|
4
|
+
const load = (name) => import(name);
|
|
5
|
+
|
|
6
|
+
function missing(error, name) {
|
|
7
|
+
if (error?.code !== 'ERR_MODULE_NOT_FOUND') return false;
|
|
8
|
+
return String(error.message).includes(`'${name}'`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function optional(name, importer) {
|
|
12
|
+
try {
|
|
13
|
+
return await importer(name);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (missing(error, name)) return null;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isFile(path) {
|
|
21
|
+
try {
|
|
22
|
+
return statSync(path).isFile();
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const HINT =
|
|
29
|
+
'no Chromium for the harness: pass launch({ executable }), set CHROME_PATH, or install @ai-ecoverse/slicc-cdp and run `npx slicc-cdp install-browser --version <x.y.z.w>` (or install playwright-core and run `npx playwright-core install chromium`)';
|
|
30
|
+
|
|
31
|
+
export function explicit(path) {
|
|
32
|
+
if (isFile(path)) return path;
|
|
33
|
+
throw new Error(`launch({ executable }) is ${path}, which is not a file`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function executablePath({ env = inherited, importer = load } = {}) {
|
|
37
|
+
if (env.CHROME_PATH) {
|
|
38
|
+
if (isFile(env.CHROME_PATH)) return env.CHROME_PATH;
|
|
39
|
+
throw new Error(`CHROME_PATH is ${env.CHROME_PATH}, which is not a file`);
|
|
40
|
+
}
|
|
41
|
+
const cdp = await optional('@ai-ecoverse/slicc-cdp', importer);
|
|
42
|
+
if (typeof cdp?.findBrowser === 'function') {
|
|
43
|
+
const found = await cdp.findBrowser({ env });
|
|
44
|
+
if (found) return found.executable;
|
|
45
|
+
}
|
|
46
|
+
const playwright = await optional('playwright-core', importer);
|
|
47
|
+
const path = playwright?.chromium?.executablePath();
|
|
48
|
+
if (path && isFile(path)) return path;
|
|
49
|
+
throw new Error(path ? `${HINT}; playwright-core's ${path} is not installed` : HINT);
|
|
50
|
+
}
|
package/harness/chrome.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { 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';
|
|
8
|
-
import {
|
|
8
|
+
import { executablePath, explicit } from './browser.mjs';
|
|
9
9
|
import { cdn } from './cdn.mjs';
|
|
10
10
|
import { CRASHED, connect, pipe } from './cdp.mjs';
|
|
11
11
|
import { crashpad } from './dumps.mjs';
|
|
@@ -80,10 +80,11 @@ export function exitOf(code, signal) {
|
|
|
80
80
|
export async function start(
|
|
81
81
|
profile,
|
|
82
82
|
args = commandLine(profile),
|
|
83
|
-
executable =
|
|
83
|
+
executable = undefined,
|
|
84
84
|
env = inherited
|
|
85
85
|
) {
|
|
86
|
-
const
|
|
86
|
+
const path = executable ?? (await executablePath({ env }));
|
|
87
|
+
const child = spawn(path, args, {
|
|
87
88
|
env,
|
|
88
89
|
detached: true,
|
|
89
90
|
stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'],
|
|
@@ -238,7 +239,9 @@ export async function launch({
|
|
|
238
239
|
profile = inherited.SLICC_PROFILE === '1',
|
|
239
240
|
realistic = false,
|
|
240
241
|
persistent = false,
|
|
242
|
+
executable,
|
|
241
243
|
} = {}) {
|
|
244
|
+
const browser = executable === undefined ? await executablePath() : explicit(executable);
|
|
242
245
|
pruning ??= prune();
|
|
243
246
|
await pruning;
|
|
244
247
|
const server = await serve({ roots, aliases, isolated });
|
|
@@ -252,9 +255,15 @@ export async function launch({
|
|
|
252
255
|
const { child, exited, stderr } = await start(
|
|
253
256
|
userData,
|
|
254
257
|
commandLine(userData, loaded, args, realistic),
|
|
255
|
-
|
|
258
|
+
browser,
|
|
256
259
|
dumps.env
|
|
257
|
-
)
|
|
260
|
+
).catch(async (error) => {
|
|
261
|
+
await server.close();
|
|
262
|
+
await Promise.all(
|
|
263
|
+
[userData, dumps.dir].map((dir) => rm(dir, { recursive: true, force: true }))
|
|
264
|
+
);
|
|
265
|
+
throw error;
|
|
266
|
+
});
|
|
258
267
|
const untrack = track(child, [userData, dumps.dir]);
|
|
259
268
|
const cdp = await connect(pipe(child.stdio[3], child.stdio[4]), {
|
|
260
269
|
exited,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.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",
|
|
@@ -61,12 +61,21 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@biomejs/biome": "2.5.15",
|
|
63
63
|
"monocart-coverage-reports": "2.13.2",
|
|
64
|
-
"playwright-core": "1.
|
|
64
|
+
"playwright-core": "1.64.0",
|
|
65
65
|
"pnpm": "12.10.1",
|
|
66
66
|
"semantic-release": "25.0.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
+
"@ai-ecoverse/slicc-cdp": "*",
|
|
69
70
|
"monocart-coverage-reports": ">=2.13.0",
|
|
70
71
|
"playwright-core": ">=1.50.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"@ai-ecoverse/slicc-cdp": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"playwright-core": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
71
80
|
}
|
|
72
81
|
}
|