@ai-ecoverse/slicc-shared-web 1.19.0 → 1.21.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 +14 -1
- package/bin/slicc-memory-peak.sh +43 -0
- package/harness/cdp.mjs +6 -1
- package/harness/chrome.mjs +61 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
|
|
|
10
10
|
| `tsconfig.json` | TypeScript base for Node's type stripping | `tsconfig.json`: `{ "extends": "@ai-ecoverse/slicc-shared-web/tsconfig.json", "include": ["src/**/*.ts"] }` |
|
|
11
11
|
| `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, and diff coverage over [only the unit tests the change reaches](#which-unit-tests-a-commit-runs) | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]` |
|
|
12
12
|
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources in `src/` (TS types are stripped first), written to `coverage/unit/lcov.info`. With `SLICC_UNIT_TESTS` set, `node --test` runs only those files ([below](#which-unit-tests-a-commit-runs)) | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
|
|
13
|
-
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps) | `lint`: `slicc-lint`, and the hooks above |
|
|
13
|
+
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps). `slicc-memory-peak` prints the job's [memory peak](#memory-peak) | `lint`: `slicc-lint`, and the hooks above |
|
|
14
14
|
| `pnpmfile.mjs` | pnpm's counterpart to the Renovate preset: an `updateConfig` hook that adds `@ai-ecoverse/*` to `minimumReleaseAgeExclude`, so pnpm 12 doesn't hold back our own fresh releases (`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`) while third-party packages keep its age check | in a repo with a pnpm lockfile, as a [config dependency](https://pnpm.io/config-dependencies) in `pnpm-workspace.yaml`: `configDependencies: { '@ai-ecoverse/slicc-shared-web': X.Y.Z }` plus `pnpmfile: node_modules/.pnpm-config/@ai-ecoverse/slicc-shared-web/pnpmfile.mjs` |
|
|
15
15
|
| `harness/` | The CDP integration-test harness, described [below](#integration-test-harness) | `import { launch } from '@ai-ecoverse/slicc-shared-web/harness'`, and `--test-global-setup=node_modules/@ai-ecoverse/slicc-shared-web/harness/global.mjs` |
|
|
16
16
|
|
|
@@ -64,6 +64,17 @@ When a command needs the version more than once, as actionlint's download does,
|
|
|
64
64
|
|
|
65
65
|
Pin only where a fixed version is genuinely needed. When a workflow rolls forward to whatever is certified, as with `@ai-ecoverse/slicc-kernel` and its certified siblings, resolve "the newest certified" at run time instead (from the npm `latest` dist-tag, say) rather than pinning and annotating it.
|
|
66
66
|
|
|
67
|
+
## Memory peak
|
|
68
|
+
|
|
69
|
+
The reusable workflow's last step, which runs even when an earlier one failed, writes one line to the log and the job summary. It gives the job's memory peak and limit in MiB, `nproc` and the runner's name, so a runner that later "lost communication" can be compared with the peak of the same job's good runs. The numbers come from cgroup v2 (`memory.peak`, `memory.max`), from the job's own cgroup first and then the root one, or else from cgroup v1 (`memory.max_usage_in_bytes`, `memory.limit_in_bytes`), and the line names the file each one came from. A value it can't read is `n/a`, and the step never fails the job. A repo whose `@ai-ecoverse/slicc-shared-web` predates the script still gets `nproc` and the runner name.
|
|
70
|
+
|
|
71
|
+
A workflow of its own (not this reusable one) gets the same line from the composite action, as its last step:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
- uses: ai-ecoverse/slicc-shared-web/.github/actions/memory-peak@<tag or sha>
|
|
75
|
+
if: always()
|
|
76
|
+
```
|
|
77
|
+
|
|
67
78
|
## Which unit tests a commit runs
|
|
68
79
|
|
|
69
80
|
The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover the staged change, then `slicc-diff-cover` on their `coverage/unit/lcov.info`, so every staged line in `src/` still has to run:
|
|
@@ -137,6 +148,8 @@ test('boots', async (t) => {
|
|
|
137
148
|
- 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`.
|
|
138
149
|
- 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)).
|
|
139
150
|
|
|
151
|
+
`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.
|
|
152
|
+
|
|
140
153
|
When one evaluation runs past `stallAfter`, the harness probes once, without interrupting the wait:
|
|
141
154
|
- 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;
|
|
142
155
|
- it saves `stall-<n>.png` (a screenshot of the page, if the renderer still answers) in the test's artifact directory;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set +e
|
|
3
|
+
own=$(sed -n 's/^0:://p' /proc/self/cgroup 2>/dev/null)
|
|
4
|
+
first() {
|
|
5
|
+
found=n/a
|
|
6
|
+
from=-
|
|
7
|
+
for file in "$@"; do
|
|
8
|
+
if [ -r "$file" ]; then
|
|
9
|
+
value=$(cat "$file" 2>/dev/null)
|
|
10
|
+
if [ -n "$value" ]; then
|
|
11
|
+
found=$value
|
|
12
|
+
from=$file
|
|
13
|
+
return
|
|
14
|
+
fi
|
|
15
|
+
fi
|
|
16
|
+
done
|
|
17
|
+
}
|
|
18
|
+
mib() {
|
|
19
|
+
case "$1" in
|
|
20
|
+
max) printf 'unlimited' ;;
|
|
21
|
+
'' | *[!0-9]*) printf 'n/a' ;;
|
|
22
|
+
*)
|
|
23
|
+
if [ "${#1}" -gt 15 ]; then
|
|
24
|
+
printf 'unlimited'
|
|
25
|
+
else
|
|
26
|
+
printf '%s MiB' $(($1 / 1048576))
|
|
27
|
+
fi
|
|
28
|
+
;;
|
|
29
|
+
esac
|
|
30
|
+
}
|
|
31
|
+
first "/sys/fs/cgroup$own/memory.peak" /sys/fs/cgroup/memory.peak /sys/fs/cgroup/memory/memory.max_usage_in_bytes
|
|
32
|
+
peak=$found
|
|
33
|
+
peak_file=$from
|
|
34
|
+
first "/sys/fs/cgroup$own/memory.max" /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes
|
|
35
|
+
limit=$found
|
|
36
|
+
limit_file=$from
|
|
37
|
+
cpus=$(nproc 2>/dev/null || echo n/a)
|
|
38
|
+
line="memory peak $(mib "$peak") ($peak_file), limit $(mib "$limit") ($limit_file), nproc $cpus, runner ${SLICC_RUNNER_NAME:-${RUNNER_NAME:-n/a}}"
|
|
39
|
+
echo "$line"
|
|
40
|
+
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
|
41
|
+
printf '### Memory\n\n%s\n' "$line" >> "$GITHUB_STEP_SUMMARY" 2>/dev/null
|
|
42
|
+
fi
|
|
43
|
+
exit 0
|
package/harness/cdp.mjs
CHANGED
|
@@ -116,7 +116,12 @@ export async function connect(url, { exited, tail = () => [] } = {}) {
|
|
|
116
116
|
const call = pending.get(message.id);
|
|
117
117
|
pending.delete(message.id);
|
|
118
118
|
if (!call) notify(message);
|
|
119
|
-
else if (message.error)
|
|
119
|
+
else if (message.error)
|
|
120
|
+
call.reject(
|
|
121
|
+
Object.assign(new Error(`${call.method}: ${message.error.message}`), {
|
|
122
|
+
cdp: message.error,
|
|
123
|
+
})
|
|
124
|
+
);
|
|
120
125
|
else call.resolve(message.result);
|
|
121
126
|
},
|
|
122
127
|
async () => die(await Promise.race([exited ?? 'socket closed', grace(2000)]))
|
package/harness/chrome.mjs
CHANGED
|
@@ -225,6 +225,66 @@ export async function prune(dir = tmpdir(), grace = GRACE) {
|
|
|
225
225
|
|
|
226
226
|
let pruning = null;
|
|
227
227
|
|
|
228
|
+
export const WAIT = 10000;
|
|
229
|
+
|
|
230
|
+
export function unguarded(cdp) {
|
|
231
|
+
const listeners = new Set();
|
|
232
|
+
let events = null;
|
|
233
|
+
cdp.on((message) => {
|
|
234
|
+
if (message.method === undefined) return;
|
|
235
|
+
events?.push(message);
|
|
236
|
+
for (const listener of listeners) {
|
|
237
|
+
try {
|
|
238
|
+
listener(message);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
queueMicrotask(() => {
|
|
241
|
+
throw error;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const off = (listener) => listeners.delete(listener);
|
|
247
|
+
const on = (listener) => {
|
|
248
|
+
listeners.add(listener);
|
|
249
|
+
return () => off(listener);
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
send: (method, params = {}, sessionId = undefined) => cdp.send(method, params, sessionId),
|
|
253
|
+
on,
|
|
254
|
+
off,
|
|
255
|
+
get events() {
|
|
256
|
+
events ??= [];
|
|
257
|
+
return events;
|
|
258
|
+
},
|
|
259
|
+
waitEvent(match, ...rest) {
|
|
260
|
+
const method = typeof match === 'string' ? match : undefined;
|
|
261
|
+
const named = method && (rest.length > 1 || typeof rest[0] === 'function');
|
|
262
|
+
const [predicate, ms = WAIT] = method ? (named ? rest : [null, ...rest]) : [match, ...rest];
|
|
263
|
+
const wanted = (event) =>
|
|
264
|
+
(!method || event.method === method) && (!predicate || predicate(event));
|
|
265
|
+
return new Promise((resolve, reject) => {
|
|
266
|
+
const timer = setTimeout(() => {
|
|
267
|
+
off(listener);
|
|
268
|
+
reject(new Error(`waitEvent ${method ?? 'predicate'}: no event in ${ms} ms`));
|
|
269
|
+
}, ms);
|
|
270
|
+
const settle = (fn, value) => {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
off(listener);
|
|
273
|
+
fn(value);
|
|
274
|
+
};
|
|
275
|
+
const listener = (event) => {
|
|
276
|
+
try {
|
|
277
|
+
if (wanted(event)) settle(resolve, event);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
settle(reject, error);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
on(listener);
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
228
288
|
export async function launch({
|
|
229
289
|
roots,
|
|
230
290
|
aliases,
|
|
@@ -347,6 +407,7 @@ export async function launch({
|
|
|
347
407
|
}
|
|
348
408
|
|
|
349
409
|
return {
|
|
410
|
+
cdp: unguarded(cdp),
|
|
350
411
|
url: server.url,
|
|
351
412
|
pid: child.pid,
|
|
352
413
|
profile: userData,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"slicc-diff-cover": "bin/slicc-diff-cover.sh",
|
|
37
37
|
"slicc-lint": "bin/slicc-lint.sh",
|
|
38
38
|
"slicc-lint-comments": "bin/slicc-lint-comments.sh",
|
|
39
|
+
"slicc-memory-peak": "bin/slicc-memory-peak.sh",
|
|
39
40
|
"slicc-minidump": "bin/slicc-minidump.mjs",
|
|
40
41
|
"slicc-no-unit-tests": "bin/slicc-no-unit-tests.sh",
|
|
41
42
|
"slicc-unit-cover": "bin/slicc-unit-cover.mjs"
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"release": "semantic-release"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
65
|
+
"@ai-ecoverse/slicc-browsers": "1.7.3",
|
|
64
66
|
"@biomejs/biome": "2.5.15",
|
|
65
67
|
"monocart-coverage-reports": "2.13.2",
|
|
66
68
|
"playwright-core": "1.64.0",
|