@ai-ecoverse/slicc-shared-web 1.24.1 → 1.25.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 +15 -2
- package/harness/chrome.mjs +39 -7
- package/harness/extension/content.js +15 -0
- package/harness/extension/frame.html +8 -0
- package/harness/extension/manifest.json +15 -0
- package/harness/extensions.mjs +31 -0
- package/harness/index.mjs +5 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ The guard's assumption is that **workers never apply or remove `cert-review-appr
|
|
|
83
83
|
|
|
84
84
|
On `merge_group`, the guard walks the first-parent merge ancestry from `head_sha` back to `base_sha`, resolves each merge's second parent to exactly one open PR, and inspects that member's actual merged delta. It checks approval against that queued head, not just whatever head the PR API currently returns. A moved head, an unexplained non-merge commit or an unapproved certification-path PR makes the group red. This assumes the queue's **merge-commit method** with two-parent synthetic merges; squash/rebase or any other unexplained ancestry fails closed. It does not call an LLM or run candidate code.
|
|
85
85
|
|
|
86
|
-
Callers use **one external `uses:` line pinned to a full commit SHA**, not a local action path or the PR's checkout. The composite executes its script from `github.action_path`, the downloaded pinned action directory. Each lane supplies one newline-separated `paths` list covering its certification workflows, reviewer/classifier/record tools and runners. The default list covers `.github/workflows/cert*.yml`, `.github/workflows/cert*.yaml`, `scripts/cert/**`, `tools/cert-review/**` and `.github/actions/cert-self-guard/**`. Inclusive repository-relative globs
|
|
86
|
+
Callers use **one external `uses:` line pinned to a full commit SHA**, not a local action path or the PR's checkout. The composite executes its script from `github.action_path`, the downloaded pinned action directory. Each lane supplies one newline-separated `paths` list covering its certification workflows, reviewer/classifier/record tools and runners. The default list covers `.github/workflows/cert*.yml`, `.github/workflows/cert*.yaml`, `scripts/cert/**`, `tools/cert-review/**` and `.github/actions/cert-self-guard/**`. Inclusive repository-relative globs are matched fail-closed, with dot semantics: a path counts as touched when Node's `path.matchesGlob` matches it, when the glob matches it with `**` crossing dot segments and `*` matching a leading dot (`dotGlob` in `changes.mjs`), or, for a literal `X/**` glob, when it starts with `X/`. So `tools/cert-review/.npmrc` and `scripts/cert/a/.b/c.mjs` need the label too; `matchesGlob` alone skips them. Negations are not supported. Include the caller's **entire cert workflow**, so changing the guard's own `uses:` line or pinned SHA is itself guarded. An empty or invalid list fails closed.
|
|
87
87
|
|
|
88
88
|
```yaml
|
|
89
89
|
on:
|
|
@@ -191,6 +191,7 @@ test('boots', async (t) => {
|
|
|
191
191
|
| `exits` | `{ urlPath: [regex, ...] }`: a breakpoint on the first line matching each pattern in that worker script, where the harness takes the worker's coverage and profile before it closes itself | none |
|
|
192
192
|
| `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 |
|
|
193
193
|
| `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 |
|
|
194
|
+
| `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` |
|
|
194
195
|
| `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` |
|
|
195
196
|
| `executable` | The Chromium binary. Without it, `$CHROME_PATH`, then slicc-cdp's `findBrowser()`, then playwright-core (see above) | found |
|
|
196
197
|
| `args` | Extra Chromium flags, such as `--host-resolver-rules` or `--ignore-certificate-errors` | none |
|
|
@@ -229,11 +230,23 @@ Why it works the way it does:
|
|
|
229
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.
|
|
230
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.
|
|
231
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.
|
|
232
|
-
- `--disable-
|
|
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
234
|
- The attach event can arrive before `Target.createTarget` returns, so new tabs wait on a slot keyed by target id.
|
|
234
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.
|
|
235
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.
|
|
236
237
|
|
|
238
|
+
## Harness extension
|
|
239
|
+
|
|
240
|
+
Real users run content-script extensions, such as password managers and Grammarly, and each one adds an isolated JavaScript world with origin `chrome-extension://<id>` to every frame of every page. Over raw CDP, `Runtime.executionContextCreated` reports it as `{ origin: 'chrome-extension://<id>', auxData: { isDefault: false, type: 'isolated' } }`. slicc-cdp#377: bios's guard took that world for a protected page and refused everything, and CI never saw it because the harness's Chrome had no extension. So every browser `launch()` starts now carries one by default.
|
|
241
|
+
|
|
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
|
+
|
|
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.
|
|
245
|
+
|
|
246
|
+
A lane that can't have it opts out explicitly, in one of two ways:
|
|
247
|
+
- `launch({ extension: false })`, for one launch;
|
|
248
|
+
- `SLICC_HARNESS_EXTENSION=0` in the test process's environment, for every launch. `1` or unset loads it; any other value is an error, so a typo never turns it off.
|
|
249
|
+
|
|
237
250
|
## Cleanup
|
|
238
251
|
|
|
239
252
|
`close()` stops Chrome and removes its profile. It asks Chrome to close, waits up to 10 s for the exit, sends `SIGKILL`, waits up to 5 s more and then moves on with a warning, so a browser that ignores `Browser.close` or a missed exit never hangs teardown. A test process that ends without `close()` still leaves nothing running:
|
package/harness/chrome.mjs
CHANGED
|
@@ -9,14 +9,21 @@ import { executablePath, explicit } from './browser.mjs';
|
|
|
9
9
|
import { cdn } from './cdn.mjs';
|
|
10
10
|
import { CRASHED, connect, pipe } from './cdp.mjs';
|
|
11
11
|
import { crashpad } from './dumps.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
BUILTIN_PATH,
|
|
14
|
+
builtinWanted,
|
|
15
|
+
extensionSource,
|
|
16
|
+
install,
|
|
17
|
+
installBuiltin,
|
|
18
|
+
unpacked,
|
|
19
|
+
} from './extensions.mjs';
|
|
13
20
|
import { page } from './page.mjs';
|
|
14
21
|
import { breakpoints, recorder } from './recorder.mjs';
|
|
15
22
|
import { serve } from './server.mjs';
|
|
16
23
|
import { artifacts, bounded, ignore, sleep, slug, TIMED_OUT } from './util.mjs';
|
|
17
24
|
|
|
18
25
|
export const flags = [
|
|
19
|
-
'--headless',
|
|
26
|
+
'--headless=new',
|
|
20
27
|
'--remote-debugging-port=0',
|
|
21
28
|
'--remote-debugging-pipe',
|
|
22
29
|
'--no-first-run',
|
|
@@ -33,20 +40,33 @@ export const flags = [
|
|
|
33
40
|
];
|
|
34
41
|
|
|
35
42
|
export const unrealistic = [
|
|
36
|
-
'--headless',
|
|
43
|
+
'--headless=new',
|
|
37
44
|
'--disable-background-timer-throttling',
|
|
38
45
|
'--disable-backgrounding-occluded-windows',
|
|
39
46
|
'--disable-renderer-backgrounding',
|
|
40
47
|
];
|
|
41
48
|
|
|
42
|
-
export function commandLine(
|
|
43
|
-
|
|
49
|
+
export function commandLine(
|
|
50
|
+
profile,
|
|
51
|
+
extensions = [],
|
|
52
|
+
extra = [],
|
|
53
|
+
realistic = false,
|
|
54
|
+
preloaded = []
|
|
55
|
+
) {
|
|
56
|
+
const all = [...preloaded, ...extensions];
|
|
57
|
+
const loaded = all.length > 0;
|
|
44
58
|
const dropped = new Set([
|
|
45
59
|
...(loaded ? ['--disable-extensions'] : []),
|
|
46
60
|
...(realistic ? unrealistic : []),
|
|
47
61
|
]);
|
|
48
62
|
const base = flags.filter((flag) => !dropped.has(flag));
|
|
49
|
-
const load = loaded
|
|
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
|
+
: [];
|
|
50
70
|
return [...base, ...load, ...extra, `--user-data-dir=${profile}`, 'about:blank'];
|
|
51
71
|
}
|
|
52
72
|
|
|
@@ -293,6 +313,7 @@ export async function launch({
|
|
|
293
313
|
exits = {},
|
|
294
314
|
intercept = [],
|
|
295
315
|
extensions = [],
|
|
316
|
+
extension = true,
|
|
296
317
|
args = [],
|
|
297
318
|
timeout,
|
|
298
319
|
stallAfter,
|
|
@@ -301,6 +322,7 @@ export async function launch({
|
|
|
301
322
|
persistent = false,
|
|
302
323
|
executable,
|
|
303
324
|
} = {}) {
|
|
325
|
+
const builtin = builtinWanted(extension, inherited);
|
|
304
326
|
const browser = executable === undefined ? await executablePath() : explicit(executable);
|
|
305
327
|
pruning ??= prune();
|
|
306
328
|
await pruning;
|
|
@@ -314,7 +336,7 @@ export async function launch({
|
|
|
314
336
|
const dumps = await crashpad();
|
|
315
337
|
const { child, exited, stderr } = await start(
|
|
316
338
|
userData,
|
|
317
|
-
commandLine(userData, loaded, args, realistic),
|
|
339
|
+
commandLine(userData, loaded, args, realistic, builtin ? [BUILTIN_PATH] : []),
|
|
318
340
|
browser,
|
|
319
341
|
dumps.env
|
|
320
342
|
).catch(async (error) => {
|
|
@@ -351,6 +373,15 @@ export async function launch({
|
|
|
351
373
|
waitForDebuggerOnStart: true,
|
|
352
374
|
flatten: true,
|
|
353
375
|
});
|
|
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;
|
|
354
385
|
await install(cdp, found);
|
|
355
386
|
|
|
356
387
|
async function tabs() {
|
|
@@ -411,6 +442,7 @@ export async function launch({
|
|
|
411
442
|
url: server.url,
|
|
412
443
|
pid: child.pid,
|
|
413
444
|
profile: userData,
|
|
445
|
+
extension: harnessExtension,
|
|
414
446
|
cdn: remote.state,
|
|
415
447
|
requests: server.requests,
|
|
416
448
|
overrides: server.overrides,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const root = document.documentElement;
|
|
2
|
+
if (root) root.dataset.sliccHarnessExtension = chrome.runtime.id;
|
|
3
|
+
const wanted = new URLSearchParams(location.search).has('slicc-extension-frame');
|
|
4
|
+
if (wanted && window === window.top) {
|
|
5
|
+
const frame = document.createElement('iframe');
|
|
6
|
+
frame.src = chrome.runtime.getURL('frame.html');
|
|
7
|
+
frame.dataset.sliccHarnessExtension = chrome.runtime.id;
|
|
8
|
+
frame.hidden = true;
|
|
9
|
+
const attach = () => (document.body ?? document.documentElement).append(frame);
|
|
10
|
+
if (document.readyState === 'loading') {
|
|
11
|
+
document.addEventListener('DOMContentLoaded', attach, { once: true });
|
|
12
|
+
} else {
|
|
13
|
+
attach();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"name": "slicc harness content script",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtijyxGxZi2jKhXS+8Le/kCpxmybs7P7tulmwdGG4pERze0UAJ1d95NwzZ3vXoND/sC+BdxPdstIBg7RvBFdFZKSOZFPqBTDHNiE40HHo+jpxjT3o1sFZQGtUIQpY9PFblnfWs0mhD0tslY4a3TVDusoMlnhZ49TWLumeShEiSgUcwDYzAaWx/PYhfl6WrvbRh4KbYPjcyVhjzvazxU+4QThzqgNr1GI/zcIBAGySiJv9P0VfJ7yg+iR/Yjmmoxz0XIZlp2vhqqICcSl884pUDYjbO9np10+887iMM0g0z9+X3CmxXNLLwIu3CVdV5ZvgEh6eOrwfRjczXlEoZkR+UwIDAQAB",
|
|
6
|
+
"content_scripts": [
|
|
7
|
+
{
|
|
8
|
+
"matches": ["<all_urls>"],
|
|
9
|
+
"js": ["content.js"],
|
|
10
|
+
"all_frames": true,
|
|
11
|
+
"run_at": "document_start"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"web_accessible_resources": [{ "resources": ["frame.html"], "matches": ["<all_urls>"] }]
|
|
15
|
+
}
|
package/harness/extensions.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
3
|
import { join, normalize, sep } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
|
|
5
6
|
export function extensionId(input) {
|
|
6
7
|
const hex = createHash('sha256').update(input).digest('hex').slice(0, 32);
|
|
@@ -33,3 +34,33 @@ export async function install(cdp, found) {
|
|
|
33
34
|
if (id !== expected) found.set(id, root);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
export const BUILTIN_PATH = fileURLToPath(new URL('./extension', import.meta.url));
|
|
39
|
+
export const BUILTIN_ID = 'ankmbodmgimjemnojmeddfcdlbocolob';
|
|
40
|
+
export const OPT_OUT = 'SLICC_HARNESS_EXTENSION';
|
|
41
|
+
|
|
42
|
+
export function builtinWanted(option, env) {
|
|
43
|
+
const value = env[OPT_OUT];
|
|
44
|
+
if (value !== undefined && value !== '0' && value !== '1') {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`${OPT_OUT} is ${JSON.stringify(value)}; set it to 0 to leave the harness extension out, or 1 (or unset) to load it`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (option !== true && option !== false) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`launch({ extension }) is ${JSON.stringify(option)}; pass false to leave the harness extension out`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return option && value !== '0';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function installBuiltin(cdp) {
|
|
58
|
+
const { id } = await cdp.send('Extensions.loadUnpacked', {
|
|
59
|
+
path: BUILTIN_PATH,
|
|
60
|
+
enableInIncognito: true,
|
|
61
|
+
});
|
|
62
|
+
if (id !== BUILTIN_ID) {
|
|
63
|
+
throw new Error(`the harness extension loaded as ${id}, not ${BUILTIN_ID}`);
|
|
64
|
+
}
|
|
65
|
+
return { id, path: BUILTIN_PATH };
|
|
66
|
+
}
|
package/harness/index.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { connect } from './cdp.mjs';
|
|
2
2
|
export { launch } from './chrome.mjs';
|
|
3
|
+
export {
|
|
4
|
+
BUILTIN_ID as EXTENSION_ID,
|
|
5
|
+
BUILTIN_PATH as EXTENSION_PATH,
|
|
6
|
+
OPT_OUT as EXTENSION_OPT_OUT,
|
|
7
|
+
} from './extensions.mjs';
|
|
3
8
|
export { isolation, serve } from './server.mjs';
|
|
4
9
|
export { slug } from './util.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.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",
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"release": "semantic-release"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@ai-ecoverse/slicc-browsers": "1.8.
|
|
65
|
+
"@ai-ecoverse/slicc-browsers": "1.8.5",
|
|
66
66
|
"@biomejs/biome": "2.5.15",
|
|
67
67
|
"monocart-coverage-reports": "2.13.2",
|
|
68
68
|
"playwright-core": "1.64.0",
|
|
69
|
-
"pnpm": "12.12.
|
|
69
|
+
"pnpm": "12.12.1",
|
|
70
70
|
"semantic-release": "25.0.9"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|