@ai-ecoverse/slicc-shared-web 1.29.11 → 1.29.13
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/bin/slicc-unit-cover.mjs +40 -3
- package/harness/chrome.mjs +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -237,7 +237,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
237
237
|
- **A staged source file missing from the lcov:** the hook fails and names it, so no file passes diff coverage just because nothing measured it. `.jsx` and `.tsx` files are not transformed for coverage, so staging one under the sources fails the hook too.
|
|
238
238
|
- **A file that won't parse:** one warning line, then every unit test.
|
|
239
239
|
|
|
240
|
-
The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A selection of more than `SLICC_UNIT_BATCH` files (60 by default) runs in batches of that size, one `test:unit` run each with its own coverage in `coverage/unit/batch-N/` (the shared `mcr.config.mjs` writes to `SLICC_UNIT_COVERAGE_DIR` when it's set), and `slicc-diff-cover` gets every batch's `lcov.info`; diff-cover counts a line covered when any batch covered it. The hook ends with one verdict line over all batches, `slicc-unit-cover: PASS …` or `slicc-unit-cover: FAIL …` (the first failing batch stops the run and fails it; diff coverage then doesn't run). That keeps the coverage merge, which grows with the number of test files, small enough for a memory-capped hook on a widely imported file. A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. In the hook the same preload bounds each test file's process (with the default `--test-isolation=process`; `none` runs no such processes, so nothing is bounded): every test gets `--test-timeout` (`SLICC_UNIT_TIMEOUT` ms, 60000 by default, `0` turns all of these bounds off), a file still running `SLICC_UNIT_TIMEOUT` ms after its tests ended (its top-level `after()` hooks get that long too) is ended, and a file whose event loop is blocked, or that has no test running and nothing finishing, for `SLICC_UNIT_TIMEOUT` + 5 s (one that hangs at top level, or a `before()` hook running that long) is killed; a test's own longer `timeout` is honoured. The FAIL verdict names each test that timed out and each file that was ended (`… was still running 60000ms after its tests ended, open handles kept it alive (TCPServerWrap)`) or killed, and such a file fails even when its tests passed. To force a full run in the hook:
|
|
240
|
+
The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A selection of more than `SLICC_UNIT_BATCH` files (60 by default) runs in batches of that size, one `test:unit` run each with its own coverage in `coverage/unit/batch-N/` (the shared `mcr.config.mjs` writes to `SLICC_UNIT_COVERAGE_DIR` when it's set), and `slicc-diff-cover` gets every batch's `lcov.info`; diff-cover counts a line covered when any batch covered it. The hook ends with one verdict line over all batches, `slicc-unit-cover: PASS …` or `slicc-unit-cover: FAIL …` (the first failing batch stops the run and fails it; diff coverage then doesn't run). That keeps the coverage merge, which grows with the number of test files, small enough for a memory-capped hook on a widely imported file. A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. In the hook the same preload bounds each test file's process (with the default `--test-isolation=process`; `none` runs no such processes, so nothing is bounded): every test gets `--test-timeout` (`SLICC_UNIT_TIMEOUT` ms, 60000 by default, `0` turns all of these bounds off), a file still running `SLICC_UNIT_TIMEOUT` ms after its tests ended (its top-level `after()` hooks get that long too) is ended, and a file whose event loop is blocked, or that has no test running and nothing finishing, for `SLICC_UNIT_TIMEOUT` + 5 s (one that hangs at top level, or a `before()` hook running that long) is killed; a test's own longer `timeout` is honoured. The FAIL verdict names each test that timed out and each file that was ended (`… was still running 60000ms after its tests ended, open handles kept it alive (TCPServerWrap)`) or killed, and such a file fails even when its tests passed. Each `test:unit` run also has a wall-clock limit, `SLICC_UNIT_BATCH_TIMEOUT` ms (600000 by default, `0` for none): past it the run's whole process group is killed and the FAIL verdict names the batch and its files, which catches anything the per-file bounds miss, such as a test with an unlimited `timeout` of its own. To force a full run in the hook:
|
|
241
241
|
|
|
242
242
|
```sh
|
|
243
243
|
SLICC_UNIT_ALL=1 git commit
|
|
@@ -300,7 +300,7 @@ test('boots', async (t) => {
|
|
|
300
300
|
- both errors end with the last five lines of the browser's stderr, and each test keeps up to 200 lines it wrote during the test in `chrome-stderr.log`.
|
|
301
301
|
- a test that saw a renderer crash, or a browser that died of anything but `SIGKILL`, keeps Chrome's minidump of it as `<id>.dmp` in its artifact directory (see [Crash dumps](#crash-dumps)).
|
|
302
302
|
|
|
303
|
-
`chrome.cdp` is the browser's own pipe, the one the harness already drives, with no session of its own: test-only, unguarded access that bypasses everything a product guard would do, and never for product code. `send(method, params, sessionId)` makes a raw call at browser level, or in any session the browser has (the harness's auto-attached ones included); a protocol error rejects with the message and keeps the error object as `error.cdp`. `on(listener)` receives every event the browser sends, as `{ method, params, sessionId }`, until `off(listener)` or the function `on` returned. `waitEvent(method, predicate, ms)` resolves with the next matching event (call it before the action that causes the event); the predicate is optional, a predicate alone works too (`waitEvent(predicate, ms)`), and it rejects after `ms` (10 s unless given). `events` is an append-only array of every event since it was first read. That is the `{ send, waitEvent, events }` client the guard runner of `@ai-ecoverse/slicc-browsers` takes, so `run(set, { client, unguarded: chrome.cdp, … })` gives it the unguarded observer that 14 of its vectors need.
|
|
303
|
+
`chrome.cdp` is the browser's own pipe, the one the harness already drives, with no session of its own: test-only, unguarded access that bypasses everything a product guard would do, and never for product code. `send(method, params, sessionId, ms)` makes a raw call at browser level, or in any session the browser has (the harness's auto-attached ones included), and rejects with `<method>: no answer in <ms> ms` after the caller's `ms` (60 s unless given); a protocol error rejects with the message and keeps the error object as `error.cdp`. `on(listener)` receives every event the browser sends, as `{ method, params, sessionId }`, until `off(listener)` or the function `on` returned. `waitEvent(method, predicate, ms)` resolves with the next matching event (call it before the action that causes the event); the predicate is optional, a predicate alone works too (`waitEvent(predicate, ms)`), and it rejects after `ms` (10 s unless given). `events` is an append-only array of every event since it was first read. That is the `{ send, waitEvent, events }` client the guard runner of `@ai-ecoverse/slicc-browsers` takes, so `run(set, { client, unguarded: chrome.cdp, … })` gives it the unguarded observer that 14 of its vectors need.
|
|
304
304
|
|
|
305
305
|
When one evaluation runs past `stallAfter`, the harness probes once, without interrupting the wait:
|
|
306
306
|
- it adds a `pending` line to `console.log` for every navigation and request of the page that has no answer yet, with its age. A worker's script loads in the worker's own session, so its request is left out. Chrome holds CDP messages to a page while a navigation is waiting for its response, so an evaluation that hangs while the page is idle usually means one of these;
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
@@ -26,6 +26,35 @@ function run(command, args, env) {
|
|
|
26
26
|
return result.status ?? 1;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function bounded(command, args, env, ms) {
|
|
30
|
+
const child = spawn(command, args, { cwd: root, env, stdio: 'inherit', detached: true });
|
|
31
|
+
const kill = (signal) => {
|
|
32
|
+
try {
|
|
33
|
+
process.kill(-child.pid, signal);
|
|
34
|
+
} catch {}
|
|
35
|
+
};
|
|
36
|
+
const forward = (signal) => () => kill(signal);
|
|
37
|
+
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'].map((name) => [name, forward(name)]);
|
|
38
|
+
for (const [name, handler] of signals) process.on(name, handler);
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
let late = false;
|
|
41
|
+
const timer =
|
|
42
|
+
ms > 0
|
|
43
|
+
? setTimeout(() => {
|
|
44
|
+
late = true;
|
|
45
|
+
kill('SIGKILL');
|
|
46
|
+
}, ms)
|
|
47
|
+
: undefined;
|
|
48
|
+
child.on('error', reject);
|
|
49
|
+
child.on('close', (status) => {
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
for (const [name, handler] of signals) process.off(name, handler);
|
|
52
|
+
if (late) kill('SIGKILL');
|
|
53
|
+
resolve({ status: status ?? 1, late });
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
29
58
|
function selection(staged) {
|
|
30
59
|
if (process.env.SLICC_UNIT_ALL === '1') return undefined;
|
|
31
60
|
try {
|
|
@@ -93,9 +122,17 @@ for (const [index, batch] of batches.entries()) {
|
|
|
93
122
|
reports.push(join(env.SLICC_UNIT_COVERAGE_DIR, 'lcov.info'));
|
|
94
123
|
say(`batch ${index + 1} of ${batches.length}: ${batch.length} files`);
|
|
95
124
|
}
|
|
96
|
-
const
|
|
125
|
+
const limit = Number(process.env.SLICC_UNIT_BATCH_TIMEOUT ?? 600000);
|
|
126
|
+
const { status, late } = await bounded('npm', ['run', '--silent', 'test:unit'], env, limit);
|
|
127
|
+
const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
|
|
128
|
+
if (late) {
|
|
129
|
+
const named = batch === undefined ? 'every unit test file' : batch.join(' ');
|
|
130
|
+
verdict(
|
|
131
|
+
false,
|
|
132
|
+
`${which} ran past ${limit}ms and ${batches.length > 1 ? 'was' : 'were'} killed (${named})${why()}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
97
135
|
if (status !== 0) {
|
|
98
|
-
const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
|
|
99
136
|
verdict(false, `${which} failed (status ${status})${why()}`);
|
|
100
137
|
}
|
|
101
138
|
}
|
package/harness/chrome.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { env as inherited } from 'node:process';
|
|
|
7
7
|
import { promisify } from 'node:util';
|
|
8
8
|
import { executablePath, explicit } from './browser.mjs';
|
|
9
9
|
import { cdn } from './cdn.mjs';
|
|
10
|
-
import { CRASHED, connect, pipe } from './cdp.mjs';
|
|
10
|
+
import { CRASHED, connect, pipe, SEND_TIMEOUT } from './cdp.mjs';
|
|
11
11
|
import { crashpad } from './dumps.mjs';
|
|
12
12
|
import {
|
|
13
13
|
builtinWanted,
|
|
@@ -262,7 +262,8 @@ export function unguarded(cdp) {
|
|
|
262
262
|
return () => off(listener);
|
|
263
263
|
};
|
|
264
264
|
return {
|
|
265
|
-
send: (method, params = {}, sessionId = undefined
|
|
265
|
+
send: (method, params = {}, sessionId = undefined, ms = SEND_TIMEOUT) =>
|
|
266
|
+
cdp.send(method, params, sessionId, ms),
|
|
266
267
|
on,
|
|
267
268
|
off,
|
|
268
269
|
get events() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.13",
|
|
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",
|