@ai-ecoverse/slicc-shared-web 2.12.2 → 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 +2 -2
- package/harness/recorder.mjs +7 -7
- package/harness/targets.mjs +59 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ The caller cancels superseded runs on pull requests only, so a push to `main` ne
|
|
|
72
72
|
|
|
73
73
|
**Deploy** runs on pull requests only, never in the merge queue, with `id-token: write` for an OIDC-authenticated deploy. The merge queue's tests therefore run without `STAGING_URL`: a test that needs it skips when it's empty. It runs the pull request's own code, so it gets no secret unless `deploy-secrets` names it: a newline- or space-separated list of secret names, which the step exports as environment variables. The pipeline's own `AWS_BEARER_TOKEN_BEDROCK`, `SLICC_ISSUES_TOKEN`, `CLOUDFLARE_API_TOKEN` and `github_token` are never exported. The command writes `url=<staging URL>` to `$GITHUB_OUTPUT`; the tests and the reviewers get it as `STAGING_URL`.
|
|
74
74
|
|
|
75
|
-
**Integration tests** install Chrome for Testing with `slicc-cdp install-browser` (with `--with-deps` where the runner has root or passwordless sudo) (`--version` from the `chrome` input, stable without it), then each runs its share of the files matching `test-glob`. `lint` plans the split once for all `shards`, so the shards can't disagree: it
|
|
75
|
+
**Integration tests** install Chrome for Testing with `slicc-cdp install-browser` (with `--with-deps` where the runner has root or passwordless sudo) (`--version` from the `chrome` input, stable without it), then each runs its share of the files matching `test-glob`. `lint` plans the split once for all `shards`, so the shards can't disagree: it weighs each file by the most it took in the last five completed runs of the same workflow that uploaded `timings` (merge queue runs first, then pull request runs, none from a fork), since a file that downloads a lot can take several times its median when the network is slow, and hands each file to the shard with the least time so far, longest first; a file without a timing counts as the average, and without any timings every file counts the same. `integration` uploads each run's `junit/**/*.times` and `junit/**/*.xml` as one `timings` artifact, so `lint` downloads one artifact per earlier run through the REST API with the job token (about a dozen requests a run, of the repo's 1,000 an hour); until a run has one, it reads the `junit-*` artifacts of the newest run that has them. Its log names the predicted seconds of each shard, how many files had timings, and from which runs. A file's time is its own wall time where `shard.cjs` recorded one: it preloads `harness/file-time.cjs` into each test file's own process, which writes the file's wall time to `junit/<shard>-<pid>.times` when it exits, so tests registered through a shared helper still count for the file that ran them. Otherwise it is the sum of the JUnit times of the tests that name the file, and Node names the file that calls `test()`. Each shard runs the repo's own `test` command unchanged: `harness/shard.cjs`, preloaded through `NODE_OPTIONS`, makes the outermost `node --test` run only the shard's files that its own patterns match, writes `junit/<shard>.xml` next to the usual spec output, and then takes itself out of the environment, so a `node --test` that a test starts runs as it would without it. Files a `node --test` call would run that are not in `test-glob` (unit tests, say, whether in the same call or another) run on shard 0 only, so nothing is dropped; when `test-glob` matches nothing, shard 0 runs the command unchanged and the others run nothing. Each call keeps its own JUnit report (`junit/<shard>-<pid>.xml` for all but the last). Each shard uploads `coverage/`, `artifacts/` and `junit/` as `integration-<shard>`. Before its tests, each shard restores the harness's download cache, `node_modules/.cache/slicc-harness/cdn` (after `npm ci`, which would remove it), from the newest cache whose key starts with `slicc-harness-cdn-<OS>-<hash of every package-lock.json and pnpm-lock.yaml>`, else `slicc-harness-cdn-<OS>-`, so a lockfile change still starts warm. The harness's `download()` lists each npm tarball and exact-version jsdelivr file it served in the file `SLICC_TEST_DOWNLOADS` names, which the shard sets to `junit/<shard>.downloads` (an older `@ai-ecoverse/slicc-shared-web` lists nothing, so its cache stays empty). Shards only restore: a cache saved on a pull request or in the merge queue would be scoped to that ref, so no later run could use it. On a push to `main`, `downloads` reads those lists from the newest successful merge queue run (else pull request run, never a fork's), restores the cache, fetches what's missing (only tarballs from `registry.npmjs.org` and exact-version files from `cdn.jsdelivr.net`), deletes what no shard listed, and saves it under the key plus a hash of the list, only when the list changed. The cache never holds packuments, attestations or other files that can change, so a restored cache can't serve stale metadata; those are fetched fresh as before. `integration` passes only when every shard did and their JUnit reports add up to at least one test that ran, not skipped, and no failure or error (the placeholder an empty shard runs doesn't count), and every file matching `test-glob` was handed to `node --test` on exactly one shard (`shard.cjs` lists the files it hands over next to its JUnit report, as `junit/<shard>-<pid>.files`, since a test registered through a helper is attributed to the helper); a file that ran on no shard or on two is named as an error, and it prints `integration: PASS <n> tests (<k> skipped) in <m> JUnit reports, <f> of <f> test-glob files on exactly one shard` or `integration: FAIL <why>`; a repo without node tests sets `require-tests: false`. Setting `NODE_OPTIONS` in `test` would replace the pipeline's own, which carry the shard preload and the JUnit reporter, so extra node flags (a bigger heap, say) go in `node-options`. `integration` is therefore the one check to require for the tests, under the caller's job name (`ci / integration`). A suite whose last step reads every test's artifacts, as this repo's `verify.mjs` does, sets `shards: 1`.
|
|
76
76
|
|
|
77
77
|
**Windows.** With `windows-test` set, a `windows` job runs after lint on pull requests and in the merge queue, on GitHub-hosted `windows-latest`: checkout, setup-node at `node-version`, `npm ci`, then `windows-test` as a PowerShell 7 (`pwsh`) command, raw like the other commands, so a package script is `npm run test:windows`; a program that exits non-zero stops it, as `bash -e` would. Its token can only read and it gets no secrets. `integration` fails unless it passed, so `ci / integration` covers it and no other check needs requiring; without the input it is skipped, costs no Windows minutes, and `integration` doesn't wait for it. This repo's own CI runs it with `node -e "process.platform==='win32'||process.exit(1)"` only on a pull request labelled `windows` (the label counts from the next push).
|
|
78
78
|
|
|
@@ -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",
|