@ai-ecoverse/slicc-shared-web 1.12.2 → 1.12.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/harness/flight.mjs +12 -1
- package/harness/page.mjs +8 -1
- package/harness/server.mjs +11 -4
- package/package.json +1 -1
package/harness/flight.mjs
CHANGED
|
@@ -14,6 +14,14 @@ export function flights(now = Date.now) {
|
|
|
14
14
|
const { request, type = 'Other', requestId } = params;
|
|
15
15
|
requests.set(requestId, { what: `${request.method} ${request.url} (${type})`, since: now() });
|
|
16
16
|
}
|
|
17
|
+
if (method === 'Network.responseReceived') {
|
|
18
|
+
const flight = requests.get(params.requestId);
|
|
19
|
+
if (flight) flight.status = params.response.status;
|
|
20
|
+
}
|
|
21
|
+
if (method === 'Network.dataReceived') {
|
|
22
|
+
const flight = requests.get(params.requestId);
|
|
23
|
+
if (flight) flight.bytes = (flight.bytes ?? 0) + params.dataLength;
|
|
24
|
+
}
|
|
17
25
|
if (done.has(method)) requests.delete(params.requestId);
|
|
18
26
|
if (method === 'Page.frameStartedNavigating') {
|
|
19
27
|
const what = `navigation to ${params.url} (${params.navigationType})`;
|
|
@@ -27,7 +35,10 @@ export function flights(now = Date.now) {
|
|
|
27
35
|
return [...navigations.values(), ...requests.values()]
|
|
28
36
|
.sort((a, b) => a.since - b.since)
|
|
29
37
|
.slice(0, 20)
|
|
30
|
-
.map(({ what, since
|
|
38
|
+
.map(({ what, since, status, bytes = 0 }) => {
|
|
39
|
+
const answer = status ? `, answered ${status} with ${bytes} bytes of body so far` : '';
|
|
40
|
+
return `pending ${what} for ${((at - since) / 1000).toFixed(1)}s${answer}`;
|
|
41
|
+
});
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
function loaded(targetId) {
|
package/harness/page.mjs
CHANGED
|
@@ -87,6 +87,10 @@ export function decoded({ value, unserializableValue }) {
|
|
|
87
87
|
|
|
88
88
|
export const STALL_AFTER = 30000;
|
|
89
89
|
|
|
90
|
+
export function unanswered(error) {
|
|
91
|
+
return /: no answer in \d+ ms$/.test(error.message);
|
|
92
|
+
}
|
|
93
|
+
|
|
90
94
|
export function page(
|
|
91
95
|
cdp,
|
|
92
96
|
{ sessionId, targetId },
|
|
@@ -152,13 +156,16 @@ export function page(
|
|
|
152
156
|
async function within(ms, fn, ...args) {
|
|
153
157
|
const deadline = Date.now() + ms;
|
|
154
158
|
let last;
|
|
159
|
+
let answered = false;
|
|
155
160
|
for (let left = ms; left > 0; left = deadline - Date.now()) {
|
|
156
161
|
try {
|
|
157
162
|
last = await run(fn, args, left);
|
|
163
|
+
answered = true;
|
|
158
164
|
if (last) return last;
|
|
159
165
|
} catch (error) {
|
|
160
166
|
if (error.fatal) throw error;
|
|
161
|
-
last = error.message;
|
|
167
|
+
if (!answered || !unanswered(error)) last = error.message;
|
|
168
|
+
answered ||= !unanswered(error);
|
|
162
169
|
}
|
|
163
170
|
await sleep(25);
|
|
164
171
|
}
|
package/harness/server.mjs
CHANGED
|
@@ -54,16 +54,23 @@ export async function serve({
|
|
|
54
54
|
requests.push(pathname);
|
|
55
55
|
if (overrides.has(pathname)) {
|
|
56
56
|
overridden.add(pathname);
|
|
57
|
+
const body = overrides.get(pathname);
|
|
57
58
|
return response
|
|
58
|
-
.writeHead(200, {
|
|
59
|
-
|
|
59
|
+
.writeHead(200, {
|
|
60
|
+
...headers,
|
|
61
|
+
'content-type': type(pathname),
|
|
62
|
+
'content-length': Buffer.byteLength(body),
|
|
63
|
+
'cache-control': 'no-cache',
|
|
64
|
+
})
|
|
65
|
+
.end(body);
|
|
60
66
|
}
|
|
61
67
|
const file = locate(pathname);
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
68
|
+
const info = file ? await stat(file).catch(() => null) : null;
|
|
69
|
+
if (!info?.isFile()) return response.writeHead(404, headers).end();
|
|
64
70
|
response.writeHead(200, {
|
|
65
71
|
...headers,
|
|
66
72
|
'content-type': type(file),
|
|
73
|
+
'content-length': info.size,
|
|
67
74
|
'cache-control': 'no-cache',
|
|
68
75
|
});
|
|
69
76
|
createReadStream(file).pipe(response);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.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",
|