@ai-ecoverse/slicc-shared-web 2.7.1 → 2.7.3

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
@@ -73,13 +73,13 @@ The caller cancels superseded runs on pull requests only, so a push to `main` ne
73
73
 
74
74
  **Reviewer** runs twice, once with [claude-code-action](https://github.com/anthropics/claude-code-action) and once with [codex-action](https://github.com/openai/codex-action), on the same prompt, whether the tests passed or not. Both run on Amazon Bedrock with the org secret `AWS_BEARER_TOKEN_BEDROCK`, in the region of the org variable `CERT_AWS_REGION` (`us-west-2` without it). Claude uses the model in `CERT_BEDROCK_MODEL` (`global.anthropic.claude-opus-5-5` without it), as the cert reviews do. Codex uses its built-in `amazon-bedrock-runtime` provider (codex-action waits for its OpenAI proxy's `<run id>.json` in `codex-home` whenever it has a prompt, so the job writes a placeholder one) and the model in `CODEX_BEDROCK_MODEL` (`global.openai.gpt-6.1-sol` without it). Models that Bedrock serves only through inference profiles, as Sol 6.1 is, need the runtime provider and the profile's `global.` id; the `amazon-bedrock` provider's endpoint doesn't list them. The job token can only read. Each reviewer gets:
75
75
 
76
- - the pull request's head as the working directory and its base in `$RUNNER_TEMP/base`, each after `npm ci` (claude-code-action needs the working directory to be a checkout, and a base nested inside it would break the head's Biome config);
77
- - `review/integration/`, every shard's artifact;
78
- - `review/context/`, from the `context` job: the pull request's diff, files and commits from git and its title, body and labels from the event, which cost no GitHub API call, then its comments and reviews and the repo's issues and recent pull requests from the REST API, each retried once and listed in `missing.txt` when the repo's `GITHUB_TOKEN` quota (1,000 requests an hour, shared by every run in the repo) runs out, rather than failing the job;
79
- - `review/browsers.json`: four headed Chrome instances on one machine (on Xvfb display `:99` when the runner has no `DISPLAY`, since headless Chrome behaves slightly differently), `head` and `base` each linked through the extension and through slicc-cli, on CDP ports 9301 to 9304. For each one the job runs `review-browser` (by default `npm run --if-present review:browser`) in that side's tree with `SLICC_REVIEW_SIDE` (`head` or `base`), `SLICC_REVIEW_LINK` (`extension` or `cli`) and `SLICC_REVIEW_CDP`, so the repo loads its own build into that browser. Every one of them also runs the [harness extension](#harness-extension) (loaded with `--load-extension`), so the review sees pages the way a user with a content-script extension does;
76
+ - the pull request's head, with full history, as the working directory, and its base in `$RUNNER_TEMP/base`, each after `npm ci` (claude-code-action needs the working directory to be a checkout, and a base nested inside it would break the head's Biome config). Everything else the reviewers get or write (the prompt, context, integration artifacts, `browsers.json`, findings and screenshots) is in `$RUNNER_TEMP/review`, outside the checkout, so a reviewer's `npm run lint` sees only the repository;
77
+ - `$RUNNER_TEMP/review/integration/`, every shard's artifact;
78
+ - `$RUNNER_TEMP/review/context/`, from the `context` job: the pull request's diff, files and commits from git and its title, body and labels from the event, which cost no GitHub API call, then its comments and reviews and the repo's issues and recent pull requests from the REST API, each retried once and listed in `missing.txt` when the repo's `GITHUB_TOKEN` quota (1,000 requests an hour, shared by every run in the repo) runs out, rather than failing the job;
79
+ - `$RUNNER_TEMP/review/browsers.json`: four headed Chrome instances on one machine (on Xvfb display `:99` when the runner has no `DISPLAY`, since headless Chrome behaves slightly differently), `head` and `base` each linked through the extension and through slicc-cli, on CDP ports 9301 to 9304. For each one the job runs `review-browser` (by default `npm run --if-present review:browser`) in that side's tree with `SLICC_REVIEW_SIDE` (`head` or `base`), `SLICC_REVIEW_LINK` (`extension` or `cli`) and `SLICC_REVIEW_CDP`, so the repo loads its own build into that browser. Every one of them also runs the [harness extension](#harness-extension) (loaded with `--load-extension`), so the review sees pages the way a user with a content-script extension does;
80
80
  - `review-prompt`, appended to the shared prompt.
81
81
 
82
- A reviewer can attach screenshots: it saves PNGs to `review/shots/` and references them in the summary, a comment or an issue as `![what it shows](shots/name.png)`. `post` uploads them to R2 (the bucket in `R2_BUCKET`, `slicc-pr-screenshots` by default, under `<repo>/pr-<n>/<commit>/<reviewer>/`) with `CLOUDFLARE_API_TOKEN`, which only `post` gets, and rewrites each reference to its public URL (`R2_PUBLIC_BASE_URL`); without the token, a reference becomes a link to the run, whose `findings-<reviewer>` artifact holds the files.
82
+ A reviewer can attach screenshots: it saves PNGs to `$RUNNER_TEMP/review/shots/` and references them in the summary, a comment or an issue as `![what it shows](shots/name.png)`. `post` uploads them to R2 (the bucket in `R2_BUCKET`, `slicc-pr-screenshots` by default, under `<repo>/pr-<n>/<commit>/<reviewer>/`) with `CLOUDFLARE_API_TOKEN`, which only `post` gets, and rewrites each reference to its public URL (`R2_PUBLIC_BASE_URL`); without the token, a reference becomes a link to the run, whose `findings-<reviewer>` artifact holds the files.
83
83
 
84
84
  Each reviewer answers with `findings.json`, held to one JSON schema:
85
85
 
@@ -265,7 +265,7 @@ SLICC_UNIT_ALL=1 git commit
265
265
 
266
266
  ## Integration-test harness
267
267
 
268
- `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`.
268
+ `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. 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`.
269
269
 
270
270
  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.
271
271
 
@@ -8,6 +8,7 @@ import { promisify } from 'node:util';
8
8
  import { executablePath, explicit } from './browser.mjs';
9
9
  import { cdn } from './cdn.mjs';
10
10
  import { CRASHED, connect, pipe, SEND_TIMEOUT } from './cdp.mjs';
11
+ import { screenFor } from './display.mjs';
11
12
  import { crashpad } from './dumps.mjs';
12
13
  import {
13
14
  builtinWanted,
@@ -137,6 +138,12 @@ export function died(child) {
137
138
 
138
139
  export const WAITS = { close: 10000, exit: 10000, kill: 5000 };
139
140
 
141
+ export async function discard(error, closing, dirs) {
142
+ await Promise.all(closing);
143
+ await Promise.all(dirs.map((dir) => rm(dir, { recursive: true, force: true })));
144
+ throw error;
145
+ }
146
+
140
147
  export async function stop(cdp, child, waits = WAITS) {
141
148
  const gone = () => child.exitCode !== null || child.signalCode !== null;
142
149
  const exited = new Promise((resolve) => child.once('exit', resolve));
@@ -205,15 +212,15 @@ export function watchdog(pid) {
205
212
  return dog;
206
213
  }
207
214
 
208
- export function track(child, paths) {
209
- const dog = watchdog(child.pid);
210
- const entry = { children: [child, dog], paths };
215
+ export function track(child, paths, others = []) {
216
+ const dogs = [child, ...others].map((tracked) => watchdog(tracked.pid));
217
+ const entry = { children: [child, ...others, ...dogs], paths };
211
218
  if (running.size === 0) hook();
212
219
  running.add(entry);
213
220
  return () => {
214
221
  running.delete(entry);
215
222
  if (running.size === 0) unhook();
216
- kill(dog);
223
+ for (const dog of dogs) kill(dog);
217
224
  };
218
225
  }
219
226
 
@@ -335,19 +342,16 @@ export async function launch({
335
342
  const userData = await mkdtemp(join(tmpdir(), PREFIX));
336
343
  const loaded = [...found.values()].map((root) => root.slice(0, -1));
337
344
  const dumps = await crashpad();
345
+ const scrap = (error, close) =>
346
+ discard(error, [server.close(), close?.()], [userData, dumps.dir]);
347
+ const screen = await screenFor(!headless || realistic, dumps.env).catch((error) => scrap(error));
338
348
  const { child, exited, stderr } = await start(
339
349
  userData,
340
350
  commandLine(userData, loaded, args, realistic, builtin, headless),
341
351
  browser,
342
- dumps.env
343
- ).catch(async (error) => {
344
- await server.close();
345
- await Promise.all(
346
- [userData, dumps.dir].map((dir) => rm(dir, { recursive: true, force: true }))
347
- );
348
- throw error;
349
- });
350
- const untrack = track(child, [userData, dumps.dir]);
352
+ screen.env
353
+ ).catch((error) => scrap(error, screen.close));
354
+ const untrack = track(child, [userData, dumps.dir], [screen.child].filter(Boolean));
351
355
  const cdp = await connect(pipe(child.stdio[3], child.stdio[4]), {
352
356
  exited,
353
357
  tail: () => stderr.tail().map((line) => `stderr: ${line}`),
@@ -381,6 +385,7 @@ export async function launch({
381
385
  return own;
382
386
  })().catch(async (error) => {
383
387
  await stop(cdp, child);
388
+ await screen.close();
384
389
  untrack();
385
390
  await rm(userData, { recursive: true, force: true });
386
391
  await Promise.all([dumps.remove(), server.close()]);
@@ -480,6 +485,7 @@ export async function launch({
480
485
  },
481
486
  async close() {
482
487
  await stop(cdp, child);
488
+ await screen.close();
483
489
  await rm(userData, { recursive: true, force: true });
484
490
  untrack();
485
491
  closed = true;
@@ -0,0 +1,71 @@
1
+ import { spawn, spawnSync } from 'node:child_process';
2
+ import { env as inherited, platform as running } from 'node:process';
3
+ import { bounded, TIMED_OUT } from './util.mjs';
4
+
5
+ const ci = (env) => Boolean(env.CI) && env.CI !== 'false' && env.CI !== '0';
6
+ const installed = () =>
7
+ spawnSync('sh', ['-c', 'command -v Xvfb'], { stdio: 'ignore' }).status === 0;
8
+
9
+ export function wantsOwnDisplay({
10
+ headed,
11
+ env = inherited,
12
+ platform = running,
13
+ has = installed,
14
+ } = {}) {
15
+ if (!headed || platform !== 'linux') return false;
16
+ if (env.DISPLAY && !ci(env)) return false;
17
+ return has();
18
+ }
19
+
20
+ function stopper(xvfb) {
21
+ const exited = new Promise((resolve) => {
22
+ if (xvfb.exitCode !== null || xvfb.signalCode !== null) resolve();
23
+ else xvfb.once('exit', resolve);
24
+ });
25
+ return async () => {
26
+ for (const signal of ['SIGTERM', 'SIGKILL']) {
27
+ try {
28
+ process.kill(-xvfb.pid, signal);
29
+ } catch {}
30
+ if ((await bounded(exited, 'Xvfb exit', 3000)) !== TIMED_OUT) return;
31
+ }
32
+ };
33
+ }
34
+
35
+ export async function ownDisplay(env = inherited) {
36
+ const xvfb = spawn(
37
+ 'Xvfb',
38
+ ['-displayfd', '3', '-screen', '0', '1920x1080x24', '-nolisten', 'tcp'],
39
+ { detached: true, stdio: ['ignore', 'ignore', 'pipe', 'pipe'] }
40
+ );
41
+ const close = stopper(xvfb);
42
+ let said = '';
43
+ xvfb.stderr.on('data', (chunk) => {
44
+ said = `${said}${chunk}`.slice(-2000);
45
+ });
46
+ const number = new Promise((resolve, reject) => {
47
+ let out = '';
48
+ xvfb.stdio[3].on('data', (chunk) => {
49
+ out += chunk;
50
+ const found = /^(\d+)\n/.exec(out);
51
+ if (found) resolve(found[1]);
52
+ });
53
+ xvfb.once('error', reject);
54
+ xvfb.once('exit', (code, signal) => reject(new Error(`Xvfb exited with ${signal ?? code}`)));
55
+ });
56
+ number.catch(() => {});
57
+ const display = await bounded(number, 'Xvfb display', 10000).catch(async (error) => {
58
+ await close();
59
+ throw new Error(`${error.message}\n${said}`);
60
+ });
61
+ if (display === TIMED_OUT) {
62
+ await close();
63
+ throw new Error(`Xvfb named no display within 10 s\n${said}`);
64
+ }
65
+ return { env: { ...env, DISPLAY: `:${display}` }, child: xvfb, close };
66
+ }
67
+
68
+ export async function screenFor(headed, env = inherited) {
69
+ if (!wantsOwnDisplay({ headed, env })) return { env, child: null, close: async () => {} };
70
+ return ownDisplay(env);
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
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",