@ai-ecoverse/slicc-shared-web 1.25.1 → 1.25.2
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 +1 -1
- package/harness/recorder.mjs +47 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,7 +218,7 @@ test('boots', async (t) => {
|
|
|
218
218
|
- the summary runs in the test process, which also serves the page's files and talks CDP, so it is linear in the trace's events: a busy page's half-million-event trace takes well under a second, and the page's fetches keep getting answers meanwhile;
|
|
219
219
|
- it adds a line for every debugger pause still held in the browser, in any target, with its id, URL, start time, reason and top call frames.
|
|
220
220
|
|
|
221
|
-
Coverage is kept as one entry per script URL, each worker's counts summed into it as the worker's coverage is taken, so a run of thousands of workers keeps no more than its distinct scripts. A worker paused at its exit breakpoint is resumed as soon as its coverage and profile are taken; the profile is written to disk after. A pause in one target blocks every page in the same renderer process, so those pause lines name the culprit even when it isn't the page under test. The harness resumes its own coverage pauses (`beforeunload`, worker exits) within 10 s, even when collecting coverage fails. Downloads of intercepted URLs time out after 60 s and are tried up to three times; a `4xx` is not retried. `chrome.requests` lists the paths the server saw in this test, `chrome.overrides` is a `Map` of paths to bodies served instead of files, and `chrome.cdn` takes `status` (answer every intercepted request with it), `corrupt` (flip the last byte) and lists the intercepted `requests`. All of them reset with each test. `serve(options)` starts the same server on its own, for an `npm start`.
|
|
221
|
+
Coverage is kept as one entry per script URL, each worker's counts summed into it as the worker's coverage is taken, so a run of thousands of workers keeps no more than its distinct scripts. A worker paused at its exit breakpoint is resumed as soon as its coverage and profile are taken; the profile is written to disk after. A pause in one target blocks every page in the same renderer process, so those pause lines name the culprit even when it isn't the page under test. The harness resumes its own coverage pauses (`beforeunload`, worker exits) within 10 s, even when collecting coverage fails. Any other pause in a session of its own, such as a `debugger;` statement, it resumes too, unless a test debugs that target in a session it attached itself (with `Target.attachToTarget` on `chrome.cdp`, say, and `Debugger.enable`): then that pause stays held for `Debugger.evaluateOnCallFrame` until the test resumes it. The harness never resumes a session the test attached, sends it no commands and takes no coverage, console lines or profiles from it. Downloads of intercepted URLs time out after 60 s and are tried up to three times; a `4xx` is not retried. `chrome.requests` lists the paths the server saw in this test, `chrome.overrides` is a `Map` of paths to bodies served instead of files, and `chrome.cdn` takes `status` (answer every intercepted request with it), `corrupt` (flip the last byte) and lists the intercepted `requests`. All of them reset with each test. `serve(options)` starts the same server on its own, for an `npm start`.
|
|
222
222
|
|
|
223
223
|
Why it works the way it does:
|
|
224
224
|
|
package/harness/recorder.mjs
CHANGED
|
@@ -11,7 +11,8 @@ const Util = mcrUtil.Util ?? mcrUtil.default;
|
|
|
11
11
|
|
|
12
12
|
const profiled = new Set(['page', 'worker', 'service_worker', 'shared_worker']);
|
|
13
13
|
const sampling = [['Profiler.setSamplingInterval', { interval: 100 }], ['Profiler.start']];
|
|
14
|
-
const
|
|
14
|
+
const unloading = 'sliccHarnessUnload';
|
|
15
|
+
const unload = `addEventListener('beforeunload', function ${unloading}() { debugger; })`;
|
|
15
16
|
|
|
16
17
|
function pathOf(url) {
|
|
17
18
|
return URL.canParse(url) ? new URL(url).pathname : '';
|
|
@@ -133,6 +134,44 @@ function contextOf(sessions, parents, sessionId) {
|
|
|
133
134
|
return undefined;
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
export function caused({ callFrames = [], hitBreakpoints = [] }, target = {}, exits = new Map()) {
|
|
138
|
+
const [top] = callFrames;
|
|
139
|
+
if (!top) return false;
|
|
140
|
+
const unloaded = target.type === 'page' && top.url === '';
|
|
141
|
+
if (unloaded && top.functionName === unloading) return true;
|
|
142
|
+
const lines = hitBreakpoints.length > 0 ? exits.get(pathOf(top.url)) : undefined;
|
|
143
|
+
return Boolean(lines?.includes(top.location.lineNumber));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function ownership(parents) {
|
|
147
|
+
const owned = new Map();
|
|
148
|
+
const targets = new Map();
|
|
149
|
+
const debugging = new Set();
|
|
150
|
+
const mine = (sessionId) => owned.get(targets.get(sessionId)) === sessionId;
|
|
151
|
+
return {
|
|
152
|
+
mine,
|
|
153
|
+
adopt({ sessionId, targetInfo }, parent) {
|
|
154
|
+
targets.set(sessionId, targetInfo.targetId);
|
|
155
|
+
if ((parent && !mine(parent)) || owned.has(targetInfo.targetId)) return false;
|
|
156
|
+
owned.set(targetInfo.targetId, sessionId);
|
|
157
|
+
if (parent) parents.set(sessionId, parent);
|
|
158
|
+
return true;
|
|
159
|
+
},
|
|
160
|
+
watch(sessionId) {
|
|
161
|
+
if (targets.has(sessionId) && !mine(sessionId)) debugging.add(sessionId);
|
|
162
|
+
},
|
|
163
|
+
held(sessionId) {
|
|
164
|
+
const targetId = targets.get(sessionId);
|
|
165
|
+
return [...debugging].some((other) => targets.get(other) === targetId);
|
|
166
|
+
},
|
|
167
|
+
drop(sessionId) {
|
|
168
|
+
if (mine(sessionId)) owned.delete(targets.get(sessionId));
|
|
169
|
+
targets.delete(sessionId);
|
|
170
|
+
debugging.delete(sessionId);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
136
175
|
export function retain(scripts, result) {
|
|
137
176
|
for (const script of result) {
|
|
138
177
|
const prev = scripts.get(script.url);
|
|
@@ -180,6 +219,7 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
180
219
|
const parents = new Map();
|
|
181
220
|
const tabs = new Map();
|
|
182
221
|
const early = [];
|
|
222
|
+
const own = ownership(parents);
|
|
183
223
|
const ours = covered(server, coverage);
|
|
184
224
|
let run = null;
|
|
185
225
|
|
|
@@ -264,12 +304,12 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
264
304
|
|
|
265
305
|
cdp.on(async ({ method, params, sessionId }) => {
|
|
266
306
|
if (method === 'Target.attachedToTarget') {
|
|
267
|
-
if (
|
|
268
|
-
await attach(params);
|
|
307
|
+
if (own.adopt(params, sessionId)) await attach(params);
|
|
269
308
|
}
|
|
270
309
|
if (method === 'Target.detachedFromTarget') {
|
|
271
310
|
sessions.delete(params.sessionId);
|
|
272
311
|
pauses.delete(params.sessionId);
|
|
312
|
+
own.drop(params.sessionId);
|
|
273
313
|
}
|
|
274
314
|
if (method === 'Runtime.consoleAPICalled') {
|
|
275
315
|
const text = params.args.map((arg) => arg.value ?? arg.description).join(' ');
|
|
@@ -279,9 +319,12 @@ export function recorder(cdp, server, { coverage = ['/'], exits = new Map(), pro
|
|
|
279
319
|
const { exception, text } = params.exceptionDetails;
|
|
280
320
|
log(sessionId, `uncaught ${exception?.description ?? text}`);
|
|
281
321
|
}
|
|
322
|
+
if (method?.startsWith('Debugger.')) own.watch(sessionId);
|
|
282
323
|
if (method === 'Debugger.paused') {
|
|
283
324
|
pauses.set(sessionId, pauseOf(sessions.get(sessionId), params));
|
|
284
|
-
|
|
325
|
+
const target = sessions.get(sessionId);
|
|
326
|
+
const resumable = !own.held(sessionId) || caused(params, target, exits);
|
|
327
|
+
if (own.mine(sessionId) && resumable) await paused(sessionId);
|
|
285
328
|
}
|
|
286
329
|
if (method === 'Debugger.resumed') pauses.delete(sessionId);
|
|
287
330
|
if (method === CRASHED) log(sessionId, params.reason);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.2",
|
|
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",
|