@ai-ecoverse/slicc-shared-web 2.0.2 → 2.1.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 CHANGED
@@ -8,9 +8,9 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
8
8
  | `.github/workflows/pipeline.yml` | The one reusable workflow, described [below](#pipeline): lint on every event; on pull requests and in the merge queue a staging deploy (if any) and sharded integration tests; on pull requests a Claude and a Codex review; on `main` a release | `jobs: { ci: { uses: ai-ecoverse/slicc-shared-web/.github/workflows/pipeline.yml@vX.Y.Z, secrets: inherit } }` |
9
9
  | `biome.json` | Formatter settings and slicc's strict linter: cognitive complexity ≤ 25, functions ≤ 150 lines, no unused variables or imports, no floating or misused promises, naming conventions, `import type`/`export type`. Test files under `test/` get slicc's test exemptions | `biome.json`: `{ "extends": ["@ai-ecoverse/slicc-shared-web/biome"] }` |
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
- | `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`: the [fail-closed snippet below](#hooks-that-fail-closed) |
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`: the [fail-closed snippet below](#hooks-that-fail-closed), and `prepare`: `slicc-install-hooks` ([one hooks directory per worktree](#one-hooks-directory-per-worktree)) |
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`. Every source file is in it, tested or not, and paths are matched relative to the repo root, so a checkout under a dot-directory such as `~/.bb/` still reports untested files to diff coverage. 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`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `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 |
13
+ | `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `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). `slicc-install-hooks` installs the hooks into [this worktree's own directory](#one-hooks-directory-per-worktree) | `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
 
@@ -204,6 +204,19 @@ pre-commit:
204
204
  - **No lefthook anywhere:** with `assert_lefthook_installed` (the shared config sets it too) the git hook exits 1 with lefthook's "Can't find lefthook in PATH … Operation is aborted", where it used to print the first line and exit 0.
205
205
  - **Lefthook found, no `node_modules` here:** the generated hook calls the lefthook of the checkout that installed it, by absolute path, so it still runs; but lefthook skips an `extends` file that doesn't exist, which would leave no jobs and pass the commit. The `shared hooks` job lives in the repo's own config, so it runs and fails with `run npm install`.
206
206
 
207
+ ## One hooks directory per worktree
208
+
209
+ Without it, every worktree of a repo shares `.git/hooks/` with the main clone, and each `lefthook install` repoints that one hook at its own worktree's lefthook, so a commit anywhere runs with whichever worktree installed last, until that worktree is deleted. A repo's `package.json` installs the hooks with:
210
+
211
+ ```json
212
+ "prepare": "slicc-install-hooks"
213
+ ```
214
+
215
+ - **What it does:** moves `core.bare` and `core.worktree` from the shared config into the main worktree's `config.worktree` (so worktrees of a bare repo stay work trees), turns on `extensions.worktreeConfig`, sets this worktree's own `core.hooksPath` (`git config --worktree`) to `worktree-hooks/` in its git directory (`.git/worktree-hooks/` in the main clone, `.git/worktrees/<name>/worktree-hooks/` in a linked worktree), then runs `lefthook install` there. Running it again changes nothing.
216
+ - **Hooks are never shared:** each worktree's hook calls its own `node_modules` lefthook, whatever another worktree installs later, and removing a worktree removes only its own hooks. Once it has run, lefthook's own `postinstall` and later `lefthook install` runs follow the same `core.hooksPath`. The first `npm install` in a new worktree runs that `postinstall` before `prepare`, so it still writes the shared `.git/hooks/` once.
217
+ - **A worktree that never ran it:** it still falls back to the shared `.git/hooks/`, which any new worktree can repoint and which fails closed as [above](#hooks-that-fail-closed), until `npm install` runs there.
218
+ - **Outside a git checkout** (a packed tarball, say) it does nothing and exits 0.
219
+
207
220
  ## Which unit tests a commit runs
208
221
 
209
222
  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:
@@ -225,7 +238,7 @@ SLICC_UNIT_ALL=1 git commit
225
238
 
226
239
  ## Integration-test harness
227
240
 
228
- `harness/` drives Chromium over raw CDP on `--remote-debugging-pipe`, as its only client, from `node --test`. Chrome runs headed, since headless Chrome behaves slightly differently, so on Linux it needs a display: the pipeline starts Xvfb when the runner has none, and elsewhere `xvfb-run -a npm test` does. 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`.
241
+ `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, and a headed run on Linux without a display needs `xvfb-run -a`. 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`.
229
242
 
230
243
  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.
231
244
 
@@ -264,13 +277,14 @@ test('boots', async (t) => {
264
277
  | `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 |
265
278
  | `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 |
266
279
  | `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` |
280
+ | `headless` | Run Chrome headless | `true` unless `CI` is set; `SLICC_HEADLESS=1` or `0` overrides |
267
281
  | `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` |
268
282
  | `executable` | The Chromium binary. Without it, `$CHROME_PATH`, then slicc-cdp's `findBrowser()`, then playwright-core (see above) | found |
269
283
  | `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
270
284
  | `timeout` | How long `page.until` polls and `page.evaluate` waits, in ms | `30000` |
271
285
  | `stallAfter` | How long one evaluation may run before the harness probes the test's targets, in ms | `30000` |
272
286
  | `profile` | Record a CPU profile of every target, sampled every 100 µs | `true` if `SLICC_PROFILE=1`, else `false` |
273
- | `realistic` | Run Chrome as a user would: without `--disable-background-timer-throttling`, `--disable-backgrounding-occluded-windows` and `--disable-renderer-backgrounding`, so a tab behind another one is hidden and throttled. For measuring background tabs | `false` |
287
+ | `realistic` | Run Chrome as a user would: headed, whatever `headless` says, and without `--disable-background-timer-throttling`, `--disable-backgrounding-occluded-windows` and `--disable-renderer-backgrounding`, so a tab behind another one is hidden and throttled. For measuring background tabs | `false` |
274
288
 
275
289
  `chrome.page(t)` opens a tab and returns the page API: `goto(path)`, `reload()`, `evaluate(fn, ...args)`, `until(fn, ...args)`, `press(key, ...modifiers)` (a key name like `Enter` or `F5`, or a single character typed with its US-layout key code), `type(text)`, `insert(text)`, `enter()`, `init(fn)` (runs in every new document), `expose(name, handler)` (a binding the page calls with a JSON string), `screenshot(file)`, `tab()` (another tab in the same context), `close()`, `send(method, params, ms)` (a raw CDP call in the tab's session), `errors`, `responses` and `dir` (the test's artifact directory). `chrome.pid` is the browser's process id and `chrome.profile` its `slicc-harness-*` profile directory in `$TMPDIR`. `goto` and `reload` wait until the new document is complete and no longer `about:blank`, and retry the navigation once if that never happens. `until` polls until the function returns a truthy value (not only strict `true`) and resolves with that value; the timeout error names the last result. `within(ms, fn, ...args)` is `until` with its own deadline, for a stage that should take a known time. `run(fn, ...args)` or `run(options, fn, ...args)` is for a job that may outlast the `timeout`: it starts `fn` in the page without holding a `Runtime.evaluate` open, then polls it every `everyMs` (1 s) with short evaluates, and resolves or rejects with the job's own result. It decides slow from hung by progress, not by the clock. Progress is a change in `marker` (a function run in the page at each poll, such as `() => window.done`) or in what `progress` returns (an async function run in Node, such as a probe of a process tree's CPU time). With either one set, a job whose progress stays the same for `quietMs` (60 s) fails with `<label>: no progress for N s after M s`, the last marker and progress values, and the page's pending requests and navigations. `maxMs` (30 min) is the outer bound for a job that keeps moving but never ends. Without a `marker` or `progress` only `maxMs` applies. `label` defaults to the start of `fn`'s source. The job's value must survive `returnByValue`, as with `evaluate`. Both stop at the deadline even if one evaluation never answers. Every CDP call has a deadline: `connect(url).send(method, params, sessionId, ms)` rejects with `<method>: no answer in <ms> ms` (60 s unless given), so a stuck page fails its test instead of hanging the run. A crash fails it at once instead:
276
290
  - when the browser dies, every pending and later call rejects with `<method>: browser exited with <signal>` (or `with code <n>`);
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ set -eu
3
+ git rev-parse --git-dir >/dev/null 2>&1 || exit 0
4
+ common="$(git rev-parse --path-format=absolute --git-common-dir)"
5
+ for key in core.bare core.worktree; do
6
+ if value=$(git config --file "$common/config" --get "$key"); then
7
+ git config --file "$common/config.worktree" --get "$key" >/dev/null || git config --file "$common/config.worktree" "$key" "$value"
8
+ git config --file "$common/config" --unset "$key"
9
+ fi
10
+ done
11
+ hooks="$(git rev-parse --absolute-git-dir)/worktree-hooks"
12
+ git config extensions.worktreeConfig true
13
+ git config --worktree core.hooksPath "$hooks"
14
+ exec lefthook install "$@"
@@ -44,12 +44,19 @@ export const unrealistic = [
44
44
  '--disable-renderer-backgrounding',
45
45
  ];
46
46
 
47
+ export function headlessByDefault(env = inherited) {
48
+ if (env.SLICC_HEADLESS === '1') return true;
49
+ if (env.SLICC_HEADLESS === '0') return false;
50
+ return !env.CI || env.CI === 'false' || env.CI === '0';
51
+ }
52
+
47
53
  export function commandLine(
48
54
  profile,
49
55
  extensions = [],
50
56
  extra = [],
51
57
  realistic = false,
52
- builtin = false
58
+ builtin = false,
59
+ headless = headlessByDefault()
53
60
  ) {
54
61
  const loaded = builtin || extensions.length > 0;
55
62
  const dropped = new Set([
@@ -58,7 +65,8 @@ export function commandLine(
58
65
  ]);
59
66
  const base = flags.filter((flag) => !dropped.has(flag));
60
67
  const load = loaded ? ['--enable-unsafe-extension-debugging'] : [];
61
- return [...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
68
+ const mode = headless && !realistic ? ['--headless=new'] : [];
69
+ return [...mode, ...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
62
70
  }
63
71
 
64
72
  export const KEPT = 200;
@@ -310,6 +318,7 @@ export async function launch({
310
318
  stallAfter,
311
319
  profile = inherited.SLICC_PROFILE === '1',
312
320
  realistic = false,
321
+ headless = headlessByDefault(),
313
322
  persistent = false,
314
323
  executable,
315
324
  } = {}) {
@@ -327,7 +336,7 @@ export async function launch({
327
336
  const dumps = await crashpad();
328
337
  const { child, exited, stderr } = await start(
329
338
  userData,
330
- commandLine(userData, loaded, args, realistic, builtin),
339
+ commandLine(userData, loaded, args, realistic, builtin, headless),
331
340
  browser,
332
341
  dumps.env
333
342
  ).catch(async (error) => {
@@ -215,6 +215,12 @@ export function commands({ type, url }, { coverage = ['/'], exits = new Map(), p
215
215
  return list;
216
216
  }
217
217
 
218
+ function destination(run, target, early) {
219
+ if (!run) return target && early;
220
+ const same = run.context === undefined || target?.browserContextId === run.context;
221
+ return same && target && run.console;
222
+ }
223
+
218
224
  export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), profiling } = {}) {
219
225
  const collecting = coverage.length > 0;
220
226
  const watching = collecting || Boolean(profiling);
@@ -277,7 +283,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
277
283
 
278
284
  function log(sessionId, line) {
279
285
  const target = sessions.get(sessionId);
280
- const into = run ? target?.browserContextId === run.context && run.console : target && early;
286
+ const into = destination(run, target, early);
281
287
  if (into) into.push(`${label(target)}: ${line}`);
282
288
  }
283
289
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "2.0.2",
3
+ "version": "2.1.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",
@@ -34,6 +34,7 @@
34
34
  "bin": {
35
35
  "slicc-agents-md": "bin/slicc-agents-md.sh",
36
36
  "slicc-diff-cover": "bin/slicc-diff-cover.sh",
37
+ "slicc-install-hooks": "bin/slicc-install-hooks.sh",
37
38
  "slicc-lint": "bin/slicc-lint.sh",
38
39
  "slicc-lint-comments": "bin/slicc-lint-comments.sh",
39
40
  "slicc-memory-peak": "bin/slicc-memory-peak.sh",
@@ -53,6 +54,7 @@
53
54
  "unit"
54
55
  ],
55
56
  "scripts": {
57
+ "prepare": "bin/slicc-install-hooks.sh",
56
58
  "lint": "bin/slicc-lint.sh && shellcheck bin/*.sh",
57
59
  "pretest": "slicc-cdp install-browser",
58
60
  "test": "SLICC_PROFILE=1 node --test --test-global-setup=harness/global.mjs test/integration/*.test.mjs && node test/integration/verify.mjs",
@@ -62,8 +64,8 @@
62
64
  "release": "semantic-release"
63
65
  },
64
66
  "devDependencies": {
65
- "@ai-ecoverse/slicc-browsers": "1.12.0",
66
- "@ai-ecoverse/slicc-cdp": "1.30.18",
67
+ "@ai-ecoverse/slicc-browsers": "1.13.0",
68
+ "@ai-ecoverse/slicc-cdp": "1.30.19",
67
69
  "@biomejs/biome": "2.5.15",
68
70
  "lefthook": "2.2.2",
69
71
  "monocart-coverage-reports": "2.13.2",