@ai-ecoverse/slicc-shared-web 1.25.0 → 1.25.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
@@ -230,7 +230,7 @@ Why it works the way it does:
230
230
  - Coverage of a script served from `chrome.overrides` would be mapped onto the file on disk, so a path overridden during a test is left out of that test's coverage.
231
231
  - A CI cache restored with a prefix key kept packuments from before a release, so pnpm in the page saw an outdated `latest` and failed with `ERR_PNPM_NO_MATCHING_VERSION`. Tarballs and versioned CDN files never change and stay cached forever; registry documents do change, so the disk copy is only the offline fallback.
232
232
  - An unscoped packument cached at `registry.npmjs.org/<name>` sat where the tarball directory `registry.npmjs.org/<name>/-/` goes, so saving one after the other failed with `EISDIR` and pnpm in the page saw `ECONNREFUSED`. Registry documents are now cached as `<path>/index.json`; a file left at the old place is a miss and is removed when something needs its place.
233
- - `--disable-component-extensions-with-background-pages`, and `--disable-extensions-except` naming only the harness extension and the `extensions` a test loads, keep a Hangouts service worker and every other extension out of every run. A launch with no extension at all keeps `--disable-extensions`.
233
+ - `--disable-component-extensions-with-background-pages` keeps a Hangouts service worker out of every run, and the fresh profile has no other extension. A launch with no extension at all keeps `--disable-extensions`. No extension goes on the command line (`--load-extension`, `--disable-extensions-except`): every extension, the harness's and a test's, loads once, through `Extensions.loadUnpacked`, because a second load gives an extension two service workers and drops its first runtime port. Once they are loaded, `launch()` fails if any target belongs to an extension it did not load.
234
234
  - The attach event can arrive before `Target.createTarget` returns, so new tabs wait on a slot keyed by target id.
235
235
  - A worker blocked in `Atomics.wait`, or one that is already gone, may never answer; snapshots give up after 3 s, and closing a context or the browser after 10 s. A call to a target that detaches or crashes fails instead of waiting forever, and a new tab that never attaches fails after 10 s.
236
236
  - A WebSocket that has closed takes new messages without an error, and a crashed target never answers, so after a crash every call used to wait out its own deadline: a browser that died 4 s in showed up as `no answer` 15 minutes later. The harness now remembers the crash or the exit and fails each call with it.
@@ -241,7 +241,7 @@ Real users run content-script extensions, such as password managers and Grammarl
241
241
 
242
242
  `harness/extension/` is an MV3 extension with no permissions, only a content script on `<all_urls>`, in all frames, at `document_start`. It sets `data-slicc-harness-extension="<id>"` on `document.documentElement`. On a page whose URL has the query flag `slicc-extension-frame` (`/?slicc-extension-frame`), it also adds a hidden `<iframe>` of its own `chrome-extension://<id>/frame.html` to the top frame, for testing extension-origin frames. Its manifest has a fixed `key`, so its id is always `ankmbodmgimjemnojmeddfcdlbocolob`, exported as `EXTENSION_ID` (and its directory as `EXTENSION_PATH`) from the harness. `chrome.extension` is `{ id, path }` for a launch that loaded it and `null` for one that didn't, so a test can assert either.
243
243
 
244
- Chrome gets `--headless=new`, which runs extensions, `--load-extension=<dir>` and `--disable-extensions-except=<dir>` (plus any `extensions` the test loads). Chrome does not run extensions in the off-the-record contexts each test gets, so once attached the harness also loads the same directory with `Extensions.loadUnpacked` and `enableInIncognito: true` (behind `--enable-unsafe-extension-debugging`). The extension then runs in every per-test context, and tests stay in their own contexts. If it loads with any other id, or not at all, `launch()` fails rather than going on without it. Its script is not counted for coverage.
244
+ Chrome gets `--headless=new`, which runs extensions, and `--enable-unsafe-extension-debugging`. Once attached, the harness loads the extension directory with `Extensions.loadUnpacked` and `enableInIncognito: true`, so it runs in the default context and in the off-the-record context each test gets, and tests stay in their own contexts. If it loads with any other id, or not at all, `launch()` fails rather than going on without it. Its script is not counted for coverage.
245
245
 
246
246
  A lane that can't have it opts out explicitly, in one of two ways:
247
247
  - `launch({ extension: false })`, for one launch;
@@ -10,8 +10,8 @@ import { cdn } from './cdn.mjs';
10
10
  import { CRASHED, connect, pipe } from './cdp.mjs';
11
11
  import { crashpad } from './dumps.mjs';
12
12
  import {
13
- BUILTIN_PATH,
14
13
  builtinWanted,
14
+ exclusive,
15
15
  extensionSource,
16
16
  install,
17
17
  installBuiltin,
@@ -51,22 +51,15 @@ export function commandLine(
51
51
  extensions = [],
52
52
  extra = [],
53
53
  realistic = false,
54
- preloaded = []
54
+ builtin = false
55
55
  ) {
56
- const all = [...preloaded, ...extensions];
57
- const loaded = all.length > 0;
56
+ const loaded = builtin || extensions.length > 0;
58
57
  const dropped = new Set([
59
58
  ...(loaded ? ['--disable-extensions'] : []),
60
59
  ...(realistic ? unrealistic : []),
61
60
  ]);
62
61
  const base = flags.filter((flag) => !dropped.has(flag));
63
- const load = loaded
64
- ? [
65
- '--enable-unsafe-extension-debugging',
66
- ...(preloaded.length > 0 ? [`--load-extension=${preloaded.join(',')}`] : []),
67
- `--disable-extensions-except=${all.join(',')}`,
68
- ]
69
- : [];
62
+ const load = loaded ? ['--enable-unsafe-extension-debugging'] : [];
70
63
  return [...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
71
64
  }
72
65
 
@@ -336,7 +329,7 @@ export async function launch({
336
329
  const dumps = await crashpad();
337
330
  const { child, exited, stderr } = await start(
338
331
  userData,
339
- commandLine(userData, loaded, args, realistic, builtin ? [BUILTIN_PATH] : []),
332
+ commandLine(userData, loaded, args, realistic, builtin),
340
333
  browser,
341
334
  dumps.env
342
335
  ).catch(async (error) => {
@@ -373,16 +366,18 @@ export async function launch({
373
366
  waitForDebuggerOnStart: true,
374
367
  flatten: true,
375
368
  });
376
- const harnessExtension = builtin
377
- ? await installBuiltin(cdp).catch(async (error) => {
378
- await stop(cdp, child);
379
- untrack();
380
- await rm(userData, { recursive: true, force: true });
381
- await Promise.all([dumps.remove(), server.close()]);
382
- throw error;
383
- })
384
- : null;
385
- await install(cdp, found);
369
+ const harnessExtension = await (async () => {
370
+ const own = builtin ? await installBuiltin(cdp) : null;
371
+ await install(cdp, found);
372
+ await exclusive(cdp, [...(own ? [own.id] : []), ...found.keys()]);
373
+ return own;
374
+ })().catch(async (error) => {
375
+ await stop(cdp, child);
376
+ untrack();
377
+ await rm(userData, { recursive: true, force: true });
378
+ await Promise.all([dumps.remove(), server.close()]);
379
+ throw error;
380
+ });
386
381
 
387
382
  async function tabs() {
388
383
  const { targetInfos } = await cdp.send('Target.getTargets');
@@ -64,3 +64,15 @@ export async function installBuiltin(cdp) {
64
64
  }
65
65
  return { id, path: BUILTIN_PATH };
66
66
  }
67
+
68
+ export async function exclusive(cdp, allowed) {
69
+ const { targetInfos } = await cdp.send('Target.getTargets');
70
+ const hosts = targetInfos
71
+ .map(({ url }) => url)
72
+ .filter((url) => url.startsWith('chrome-extension://'))
73
+ .map((url) => new URL(url).host);
74
+ const foreign = [...new Set(hosts)].filter((host) => !allowed.includes(host));
75
+ if (foreign.length > 0) {
76
+ throw new Error(`Chrome loaded extensions the harness did not ask for: ${foreign.join(', ')}`);
77
+ }
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.25.0",
3
+ "version": "1.25.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",