@enhance-eng/sdk 0.1.0-dev.sha-d9190c779d58 → 0.1.158
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 +79 -11
- package/dist/browser/kernel.iife.js +4598 -3208
- package/dist/capture-client.client--zU5zvd3.d.mts +78 -0
- package/dist/capture-client.client-YvUy2nGh.mjs +525 -0
- package/dist/capture-context.lib-BivWcwWc.mjs +40 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.mjs +1 -1
- package/dist/{environment.config-DW6wFq6z.mjs → environment.config-B2WQJWaS.mjs} +3 -3
- package/dist/{environment.config-CA-3pMfN.d.mts → environment.config-Dx5WHap5.d.mts} +1 -1
- package/dist/index-7uzK6oto.d.mts +656 -0
- package/dist/index.d.mts +9 -5
- package/dist/index.mjs +3 -3
- package/dist/{package-CLHe5Seu.mjs → package-VWmCi21a.mjs} +1 -1
- package/dist/playwright/index.d.mts +7 -1
- package/dist/playwright/index.mjs +614 -6174
- package/dist/playwright/reporter.d.mts +4 -4
- package/dist/playwright/reporter.mjs +97 -26
- package/dist/stall-watch.lib-C6VmIsz-.mjs +8474 -0
- package/package.json +13 -6
- package/dist/capture-client.client-BDphetFj.mjs +0 -226
- package/dist/capture-client.client-DsMSGK3h.d.mts +0 -34
- package/dist/capture-files.lib-BA_KBz9W.mjs +0 -406
- package/dist/capture-files.lib-BpwdV8DQ.d.mts +0 -266
- package/dist/environment.config-D898JKZB.mjs +0 -10
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import nodePath from "node:path";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
//#region ../contract/src/capture/capture.schema.ts
|
|
6
|
-
const CAPTURE_KEY_LENGTH = 160;
|
|
7
|
-
const CAPTURE_MAX_EDGE = 32768;
|
|
8
|
-
const CAPTURE_METADATA_LENGTH = 200;
|
|
9
|
-
const CAPTURE_MAX_ORDER = 1e5;
|
|
10
|
-
const CAPTURE_MAX_PIXEL_RATIO = 8;
|
|
11
|
-
const CAPTURE_URL_LENGTH = 8192;
|
|
12
|
-
const CAPTURE_MAX_ASSETS = 2e3;
|
|
13
|
-
const CAPTURE_ISSUE_LENGTH = 500;
|
|
14
|
-
const CAPTURE_MAX_ISSUES = 100;
|
|
15
|
-
const CAPTURE_MAX_PARTICIPANTS = 128;
|
|
16
|
-
const CAPTURE_MAX_ATTEMPTS = 1e4;
|
|
17
|
-
const CAPTURE_FAILURE_LENGTH = 1e3;
|
|
18
|
-
const CAPTURE_UPLOAD_BATCH_SIZE = 400;
|
|
19
|
-
const CAPTURE_MAX_BLOB_BYTES = 16777216;
|
|
20
|
-
const key = z.string().trim().min(1).max(CAPTURE_KEY_LENGTH);
|
|
21
|
-
const digest = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
22
|
-
const dimension = z.number().int().positive().max(CAPTURE_MAX_EDGE);
|
|
23
|
-
const captureKeySchema = z.strictObject({
|
|
24
|
-
source: key,
|
|
25
|
-
journey: key,
|
|
26
|
-
step: key,
|
|
27
|
-
variant: key
|
|
28
|
-
});
|
|
29
|
-
const captureBlobSchema = z.strictObject({
|
|
30
|
-
sha256: digest,
|
|
31
|
-
bytes: z.number().int().positive().max(CAPTURE_MAX_BLOB_BYTES),
|
|
32
|
-
mediaType: z.string().min(1).max(CAPTURE_METADATA_LENGTH)
|
|
33
|
-
});
|
|
34
|
-
const captureArtifactSchema = z.strictObject({
|
|
35
|
-
format: z.literal("enhance-capture"),
|
|
36
|
-
version: z.literal(1),
|
|
37
|
-
key: captureKeySchema,
|
|
38
|
-
label: key,
|
|
39
|
-
journeyLabel: key,
|
|
40
|
-
order: z.number().int().nonnegative().max(CAPTURE_MAX_ORDER),
|
|
41
|
-
viewport: z.strictObject({
|
|
42
|
-
width: dimension,
|
|
43
|
-
height: dimension,
|
|
44
|
-
deviceScaleFactor: z.number().positive().max(CAPTURE_MAX_PIXEL_RATIO)
|
|
45
|
-
}),
|
|
46
|
-
extent: z.enum(["viewport", "full-page"]),
|
|
47
|
-
source: z.strictObject({
|
|
48
|
-
format: z.literal("rrweb-screen"),
|
|
49
|
-
version: z.literal(1),
|
|
50
|
-
blob: captureBlobSchema
|
|
51
|
-
}),
|
|
52
|
-
preview: z.strictObject({
|
|
53
|
-
blob: captureBlobSchema,
|
|
54
|
-
width: dimension,
|
|
55
|
-
height: dimension,
|
|
56
|
-
pixelRatio: z.number().positive().max(CAPTURE_MAX_PIXEL_RATIO)
|
|
57
|
-
}),
|
|
58
|
-
assets: z.array(z.strictObject({
|
|
59
|
-
url: z.url().max(CAPTURE_URL_LENGTH),
|
|
60
|
-
blob: captureBlobSchema
|
|
61
|
-
})).max(CAPTURE_MAX_ASSETS),
|
|
62
|
-
provenance: z.strictObject({
|
|
63
|
-
adapter: key,
|
|
64
|
-
sdkVersion: key,
|
|
65
|
-
kernelVersion: key,
|
|
66
|
-
browser: key,
|
|
67
|
-
capturedAt: z.iso.datetime(),
|
|
68
|
-
sourceUrl: z.url().max(CAPTURE_URL_LENGTH).optional(),
|
|
69
|
-
commit: z.string().min(1).max(CAPTURE_METADATA_LENGTH).optional()
|
|
70
|
-
}),
|
|
71
|
-
issues: z.array(z.strictObject({
|
|
72
|
-
code: key,
|
|
73
|
-
message: z.string().min(1).max(CAPTURE_ISSUE_LENGTH)
|
|
74
|
-
})).max(CAPTURE_MAX_ISSUES)
|
|
75
|
-
}).superRefine((artifact, ctx) => {
|
|
76
|
-
if (artifact.preview.width * artifact.preview.height > 16e6) ctx.addIssue({
|
|
77
|
-
code: "custom",
|
|
78
|
-
path: ["preview"],
|
|
79
|
-
message: "Capture previews are limited to 16 million pixels."
|
|
80
|
-
});
|
|
81
|
-
if (artifact.preview.width / artifact.preview.pixelRatio !== artifact.viewport.width || artifact.preview.height / artifact.preview.pixelRatio !== artifact.viewport.height) ctx.addIssue({
|
|
82
|
-
code: "custom",
|
|
83
|
-
path: ["preview"],
|
|
84
|
-
message: "The preview and captured CSS extent must match."
|
|
85
|
-
});
|
|
86
|
-
if (artifact.source.blob.mediaType !== "application/json") ctx.addIssue({
|
|
87
|
-
code: "custom",
|
|
88
|
-
path: [
|
|
89
|
-
"source",
|
|
90
|
-
"blob",
|
|
91
|
-
"mediaType"
|
|
92
|
-
],
|
|
93
|
-
message: "Capture sources must be frozen JSON."
|
|
94
|
-
});
|
|
95
|
-
if (artifact.preview.blob.mediaType !== "image/png") ctx.addIssue({
|
|
96
|
-
code: "custom",
|
|
97
|
-
path: [
|
|
98
|
-
"preview",
|
|
99
|
-
"blob",
|
|
100
|
-
"mediaType"
|
|
101
|
-
],
|
|
102
|
-
message: "Capture previews must be PNG."
|
|
103
|
-
});
|
|
104
|
-
if (new Set(artifact.assets.map((asset) => asset.url)).size !== artifact.assets.length) ctx.addIssue({
|
|
105
|
-
code: "custom",
|
|
106
|
-
path: ["assets"],
|
|
107
|
-
message: "Capture resource URLs must be unique."
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
const captureRunDescriptorSchema = z.strictObject({
|
|
111
|
-
id: z.uuid(),
|
|
112
|
-
canvasId: z.uuid(),
|
|
113
|
-
source: key,
|
|
114
|
-
runKey: key,
|
|
115
|
-
generation: z.number().int().nonnegative(),
|
|
116
|
-
participants: z.array(key).min(1).max(CAPTURE_MAX_PARTICIPANTS),
|
|
117
|
-
expiresAt: z.iso.datetime(),
|
|
118
|
-
formatVersion: z.literal(1)
|
|
119
|
-
});
|
|
120
|
-
const captureAttemptSchema = z.strictObject({
|
|
121
|
-
participant: key,
|
|
122
|
-
testId: key,
|
|
123
|
-
project: key,
|
|
124
|
-
retry: z.number().int().nonnegative().max(CAPTURE_MAX_ISSUES),
|
|
125
|
-
status: z.enum([
|
|
126
|
-
"passed",
|
|
127
|
-
"failed",
|
|
128
|
-
"skipped",
|
|
129
|
-
"interrupted",
|
|
130
|
-
"timedOut"
|
|
131
|
-
]),
|
|
132
|
-
captures: z.array(captureArtifactSchema).max(64)
|
|
133
|
-
});
|
|
134
|
-
const captureManifestSchema = z.strictObject({
|
|
135
|
-
format: z.literal("enhance-capture-run"),
|
|
136
|
-
version: z.literal(1),
|
|
137
|
-
run: captureRunDescriptorSchema,
|
|
138
|
-
participants: z.array(z.strictObject({
|
|
139
|
-
id: key,
|
|
140
|
-
status: z.enum([
|
|
141
|
-
"passed",
|
|
142
|
-
"failed",
|
|
143
|
-
"interrupted"
|
|
144
|
-
])
|
|
145
|
-
})).min(1).max(CAPTURE_MAX_PARTICIPANTS),
|
|
146
|
-
attempts: z.array(captureAttemptSchema).max(CAPTURE_MAX_ATTEMPTS),
|
|
147
|
-
ordering: z.enum(["partial", "complete"])
|
|
148
|
-
});
|
|
149
|
-
const captureReceiptSchema = z.strictObject({
|
|
150
|
-
runId: z.uuid(),
|
|
151
|
-
canvasId: z.uuid(),
|
|
152
|
-
canvasUrl: z.url(),
|
|
153
|
-
version: z.number().int().positive(),
|
|
154
|
-
manifestDigest: digest,
|
|
155
|
-
frames: z.array(z.strictObject({
|
|
156
|
-
key: captureKeySchema,
|
|
157
|
-
frameId: key,
|
|
158
|
-
captureId: z.uuid()
|
|
159
|
-
})).max(64),
|
|
160
|
-
issues: z.array(z.strictObject({
|
|
161
|
-
code: key,
|
|
162
|
-
message: z.string().max(CAPTURE_ISSUE_LENGTH)
|
|
163
|
-
})).max(CAPTURE_MAX_ISSUES)
|
|
164
|
-
});
|
|
165
|
-
const beginCaptureRunInputSchema = z.strictObject({
|
|
166
|
-
canvasId: z.uuid(),
|
|
167
|
-
source: key.default("default"),
|
|
168
|
-
runKey: key,
|
|
169
|
-
participants: z.array(key).min(1).max(CAPTURE_MAX_PARTICIPANTS).default(["local"]),
|
|
170
|
-
formatVersion: z.literal(1).default(1)
|
|
171
|
-
});
|
|
172
|
-
const beginCaptureRunOutputSchema = z.strictObject({ run: captureRunDescriptorSchema });
|
|
173
|
-
z.strictObject({ runId: z.uuid() });
|
|
174
|
-
const captureRunStateSchema = z.enum([
|
|
175
|
-
"collecting",
|
|
176
|
-
"sealed",
|
|
177
|
-
"converting",
|
|
178
|
-
"committed",
|
|
179
|
-
"failed",
|
|
180
|
-
"cancelled"
|
|
181
|
-
]);
|
|
182
|
-
const getCaptureRunOutputSchema = z.strictObject({
|
|
183
|
-
run: captureRunDescriptorSchema,
|
|
184
|
-
state: captureRunStateSchema,
|
|
185
|
-
receipt: captureReceiptSchema.nullable(),
|
|
186
|
-
failure: z.strictObject({
|
|
187
|
-
code: key,
|
|
188
|
-
message: z.string().max(CAPTURE_FAILURE_LENGTH)
|
|
189
|
-
}).nullable()
|
|
190
|
-
});
|
|
191
|
-
z.strictObject({
|
|
192
|
-
runId: z.uuid(),
|
|
193
|
-
blobs: z.array(captureBlobSchema).min(1).max(CAPTURE_UPLOAD_BATCH_SIZE)
|
|
194
|
-
});
|
|
195
|
-
const reserveCaptureBlobsOutputSchema = z.strictObject({ uploads: z.array(z.strictObject({
|
|
196
|
-
sha256: digest,
|
|
197
|
-
upload: z.strictObject({
|
|
198
|
-
url: z.url(),
|
|
199
|
-
headers: z.record(z.string(), z.string()),
|
|
200
|
-
expiresAt: z.iso.datetime()
|
|
201
|
-
}).nullable()
|
|
202
|
-
})).max(CAPTURE_UPLOAD_BATCH_SIZE) });
|
|
203
|
-
z.strictObject({ manifest: captureManifestSchema });
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region ../contract/src/capture/capture-comparison.schema.ts
|
|
206
|
-
const COMMIT_LENGTH = 200;
|
|
207
|
-
z.strictObject({
|
|
208
|
-
canvasId: z.uuid(),
|
|
209
|
-
frameId: z.string().min(1),
|
|
210
|
-
captureId: z.uuid()
|
|
211
|
-
});
|
|
212
|
-
const preview = z.strictObject({
|
|
213
|
-
captureId: z.uuid(),
|
|
214
|
-
capturedAt: z.iso.datetime(),
|
|
215
|
-
commit: z.string().max(COMMIT_LENGTH).optional(),
|
|
216
|
-
url: z.string().min(1),
|
|
217
|
-
width: z.number().positive(),
|
|
218
|
-
height: z.number().positive(),
|
|
219
|
-
pixelRatio: z.number().positive()
|
|
220
|
-
});
|
|
221
|
-
z.strictObject({
|
|
222
|
-
frameId: z.string(),
|
|
223
|
-
before: preview,
|
|
224
|
-
after: preview
|
|
225
|
-
});
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region ../contract/src/capture/capture-manifest.lib.ts
|
|
228
|
-
const captureKeyString = (key) => JSON.stringify([
|
|
229
|
-
key.source,
|
|
230
|
-
key.journey,
|
|
231
|
-
key.step,
|
|
232
|
-
key.variant
|
|
233
|
-
]);
|
|
234
|
-
const compare = (left, right) => left < right ? -1 : left === right ? 0 : 1;
|
|
235
|
-
const MAX_JSON_DEPTH = 64;
|
|
236
|
-
const canonical = (value, ancestors) => {
|
|
237
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
238
|
-
if (typeof value === "number" && Number.isFinite(value)) return JSON.stringify(value);
|
|
239
|
-
if (typeof value !== "object" || ancestors.has(value) || ancestors.size >= MAX_JSON_DEPTH) return null;
|
|
240
|
-
const next = new Set(ancestors);
|
|
241
|
-
next.add(value);
|
|
242
|
-
if (Array.isArray(value)) {
|
|
243
|
-
const entries = value.map((entry) => canonical(entry, next));
|
|
244
|
-
return entries.includes(null) ? null : `[${entries.join(",")}]`;
|
|
245
|
-
}
|
|
246
|
-
if (Object.getPrototypeOf(value) !== Object.prototype) return null;
|
|
247
|
-
const entries = Object.keys(value).toSorted(compare).map((key) => {
|
|
248
|
-
const child = canonical(Reflect.get(value, key), next);
|
|
249
|
-
return child === null ? null : `${JSON.stringify(key)}:${child}`;
|
|
250
|
-
});
|
|
251
|
-
return entries.includes(null) ? null : `{${entries.join(",")}}`;
|
|
252
|
-
};
|
|
253
|
-
/** Null means a value would be lost or coerced by JSON; it must never be hashed. */
|
|
254
|
-
const canonicalCaptureJson = (value) => canonical(value, /* @__PURE__ */ new Set());
|
|
255
|
-
const captureBlobs = (artifacts) => {
|
|
256
|
-
const blobs = /* @__PURE__ */ new Map();
|
|
257
|
-
const unique = [];
|
|
258
|
-
let totalBytes = 0;
|
|
259
|
-
for (const artifact of artifacts) {
|
|
260
|
-
const references = [
|
|
261
|
-
artifact.source.blob,
|
|
262
|
-
artifact.preview.blob,
|
|
263
|
-
...artifact.assets.map((asset) => asset.blob)
|
|
264
|
-
];
|
|
265
|
-
for (const blob of references) {
|
|
266
|
-
const previous = blobs.get(blob.sha256);
|
|
267
|
-
if (previous !== void 0 && canonicalCaptureJson(previous) !== canonicalCaptureJson(blob)) return "The same capture digest has conflicting blob metadata.";
|
|
268
|
-
if (previous === void 0) {
|
|
269
|
-
unique.push(blob);
|
|
270
|
-
totalBytes += blob.bytes;
|
|
271
|
-
blobs.set(blob.sha256, blob);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (totalBytes > 268435456) return "Capture run exceeds the retained byte budget.";
|
|
276
|
-
return unique.toSorted((a, b) => compare(a.sha256, b.sha256));
|
|
277
|
-
};
|
|
278
|
-
const finalAttempts = (manifest) => {
|
|
279
|
-
const expected = new Set(manifest.run.participants);
|
|
280
|
-
if (expected.size !== manifest.run.participants.length || manifest.participants.length !== expected.size || new Set(manifest.participants.map((part) => part.id)).size !== expected.size || manifest.participants.some((part) => !expected.has(part.id) || part.status !== "passed")) return "Every reserved participant must finish successfully exactly once.";
|
|
281
|
-
const attempts = /* @__PURE__ */ new Map();
|
|
282
|
-
const terminal = /* @__PURE__ */ new Map();
|
|
283
|
-
for (const attempt of manifest.attempts) {
|
|
284
|
-
if (!expected.has(attempt.participant)) return "Capture attempt belongs to an unreserved participant.";
|
|
285
|
-
const identity = JSON.stringify([
|
|
286
|
-
attempt.participant,
|
|
287
|
-
attempt.project,
|
|
288
|
-
attempt.testId
|
|
289
|
-
]);
|
|
290
|
-
const attemptKey = JSON.stringify([identity, attempt.retry]);
|
|
291
|
-
const content = canonicalCaptureJson(attempt);
|
|
292
|
-
if (content === null) return "Capture attempts must contain finite JSON values.";
|
|
293
|
-
const previous = terminal.get(attemptKey);
|
|
294
|
-
if (previous !== void 0 && previous !== content) return "Conflicting terminal records for the same test attempt.";
|
|
295
|
-
terminal.set(attemptKey, content);
|
|
296
|
-
const selected = attempts.get(identity);
|
|
297
|
-
if (selected === void 0 || selected.retry < attempt.retry) attempts.set(identity, attempt);
|
|
298
|
-
}
|
|
299
|
-
return manifest.attempts.filter((attempt) => attempts.get(JSON.stringify([
|
|
300
|
-
attempt.participant,
|
|
301
|
-
attempt.project,
|
|
302
|
-
attempt.testId
|
|
303
|
-
])) === attempt);
|
|
304
|
-
};
|
|
305
|
-
const uniqueCaptures = (source, artifacts) => {
|
|
306
|
-
const keys = /* @__PURE__ */ new Set();
|
|
307
|
-
const orders = /* @__PURE__ */ new Set();
|
|
308
|
-
for (const artifact of artifacts) {
|
|
309
|
-
if (artifact.key.source !== source) return "Capture source differs from its reserved run.";
|
|
310
|
-
const identity = captureKeyString(artifact.key);
|
|
311
|
-
if (keys.has(identity)) return `Duplicate capture key: ${identity}`;
|
|
312
|
-
const order = JSON.stringify([
|
|
313
|
-
artifact.key.journey,
|
|
314
|
-
artifact.key.variant,
|
|
315
|
-
artifact.order
|
|
316
|
-
]);
|
|
317
|
-
if (orders.has(order)) return `Duplicate step order in journey ${artifact.key.journey}.`;
|
|
318
|
-
keys.add(identity);
|
|
319
|
-
orders.add(order);
|
|
320
|
-
}
|
|
321
|
-
return null;
|
|
322
|
-
};
|
|
323
|
-
const compareCaptureArtifacts = (left, right) => {
|
|
324
|
-
const journey = compare(left.key.journey, right.key.journey);
|
|
325
|
-
if (journey !== 0) return journey;
|
|
326
|
-
const variant = compare(left.key.variant, right.key.variant);
|
|
327
|
-
return variant === 0 ? left.order - right.order : variant;
|
|
328
|
-
};
|
|
329
|
-
/** All publishers select whole terminal attempts with the same completeness rules. */
|
|
330
|
-
const selectedCaptures = (input) => {
|
|
331
|
-
const parsed = captureManifestSchema.safeParse(input);
|
|
332
|
-
if (!parsed.success) return "Invalid capture manifest.";
|
|
333
|
-
const manifest = parsed.data;
|
|
334
|
-
const attempts = finalAttempts(manifest);
|
|
335
|
-
if (typeof attempts === "string") return attempts;
|
|
336
|
-
const artifacts = attempts.flatMap((attempt) => attempt.status === "passed" ? attempt.captures : []);
|
|
337
|
-
if (artifacts.length === 0 || artifacts.length > 64) return `A run must contain 1–${String(64)} successful captures.`;
|
|
338
|
-
const conflict = uniqueCaptures(manifest.run.source, artifacts);
|
|
339
|
-
if (conflict !== null) return conflict;
|
|
340
|
-
const blobs = captureBlobs(artifacts);
|
|
341
|
-
return typeof blobs === "string" ? blobs : artifacts.toSorted(compareCaptureArtifacts);
|
|
342
|
-
};
|
|
343
|
-
const captureManifestContent = (manifest) => {
|
|
344
|
-
const serialized = canonicalCaptureJson(manifest);
|
|
345
|
-
return serialized === null ? null : `enhance-capture-run:v1\0${serialized}`;
|
|
346
|
-
};
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/core/capture-error.error.ts
|
|
349
|
-
const captureError = (code, message, runId) => Object.assign(new Error(message), {
|
|
350
|
-
code,
|
|
351
|
-
...runId !== void 0 && { runId }
|
|
352
|
-
});
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/node/capture-digest.lib.ts
|
|
355
|
-
const captureBlobDigest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
356
|
-
const captureManifestDigest = (manifest) => {
|
|
357
|
-
const canonical = captureManifestContent(manifest);
|
|
358
|
-
if (canonical === null) throw new Error("A capture manifest must contain only finite JSON values.");
|
|
359
|
-
return createHash("sha256").update(canonical).digest("hex");
|
|
360
|
-
};
|
|
361
|
-
//#endregion
|
|
362
|
-
//#region src/node/capture-files.lib.ts
|
|
363
|
-
const captureBlobPath = (directory, digest) => {
|
|
364
|
-
if (!/^[a-f0-9]{64}$/u.test(digest)) throw captureError("artifact", "Invalid capture blob digest.");
|
|
365
|
-
return nodePath.join(nodePath.resolve(directory), "blobs", digest);
|
|
366
|
-
};
|
|
367
|
-
const readCaptureBlob = async (directory, description) => {
|
|
368
|
-
const path = captureBlobPath(directory, description.sha256);
|
|
369
|
-
const info = await stat(path);
|
|
370
|
-
if (!info.isFile() || info.size !== description.bytes || info.size > 16777216) throw captureError("artifact", `Capture blob size does not match ${description.sha256}.`);
|
|
371
|
-
const bytes = await readFile(path);
|
|
372
|
-
if (captureBlobDigest(bytes) !== description.sha256) throw captureError("artifact", `Capture blob checksum does not match ${description.sha256}.`);
|
|
373
|
-
return bytes;
|
|
374
|
-
};
|
|
375
|
-
const writeCapturePayload = async (directory, payload) => {
|
|
376
|
-
const artifact = captureArtifactSchema.parse(payload.artifact);
|
|
377
|
-
await mkdir(nodePath.join(directory, "blobs"), { recursive: true });
|
|
378
|
-
for (const blob of payload.blobs) {
|
|
379
|
-
if (blob.description.bytes !== blob.bytes.byteLength || blob.bytes.byteLength > 16777216 || captureBlobDigest(blob.bytes) !== blob.description.sha256) throw captureError("artifact", "Capture blob bytes do not match their descriptor.");
|
|
380
|
-
const path = captureBlobPath(directory, blob.description.sha256);
|
|
381
|
-
const temporary = `${path}.${globalThis.crypto.randomUUID()}.tmp`;
|
|
382
|
-
await writeFile(temporary, blob.bytes, {
|
|
383
|
-
flag: "wx",
|
|
384
|
-
mode: 384
|
|
385
|
-
});
|
|
386
|
-
await rename(temporary, path);
|
|
387
|
-
}
|
|
388
|
-
for (const blob of [
|
|
389
|
-
artifact.source.blob,
|
|
390
|
-
artifact.preview.blob,
|
|
391
|
-
...artifact.assets.map((asset) => asset.blob)
|
|
392
|
-
]) await readCaptureBlob(directory, blob);
|
|
393
|
-
return artifact;
|
|
394
|
-
};
|
|
395
|
-
const writeCaptureJson = async (path, value) => {
|
|
396
|
-
const temporary = `${path}.${globalThis.crypto.randomUUID()}.tmp`;
|
|
397
|
-
await writeFile(temporary, JSON.stringify(value), { mode: 384 });
|
|
398
|
-
await rename(temporary, path);
|
|
399
|
-
};
|
|
400
|
-
const readCaptureManifest = async (path) => {
|
|
401
|
-
if ((await stat(path)).size > 16777216) throw captureError("artifact", "Capture manifest exceeds its byte budget.");
|
|
402
|
-
const raw = JSON.parse(await readFile(path, "utf8"));
|
|
403
|
-
return captureManifestSchema.parse(raw);
|
|
404
|
-
};
|
|
405
|
-
//#endregion
|
|
406
|
-
export { reserveCaptureBlobsOutputSchema as _, captureBlobDigest as a, canonicalCaptureJson as c, beginCaptureRunInputSchema as d, beginCaptureRunOutputSchema as f, getCaptureRunOutputSchema as g, captureRunDescriptorSchema as h, writeCapturePayload as i, captureBlobs as l, captureManifestSchema as m, readCaptureManifest as n, captureManifestDigest as o, captureArtifactSchema as p, writeCaptureJson as r, captureError as s, readCaptureBlob as t, selectedCaptures as u };
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
//#region ../contract/src/capture/capture.schema.d.ts
|
|
3
|
-
declare const captureBlobSchema: z.ZodObject<{
|
|
4
|
-
sha256: z.ZodString;
|
|
5
|
-
bytes: z.ZodNumber;
|
|
6
|
-
mediaType: z.ZodString;
|
|
7
|
-
}, z.core.$strict>;
|
|
8
|
-
type CaptureBlob = z.infer<typeof captureBlobSchema>;
|
|
9
|
-
declare const captureArtifactSchema: z.ZodObject<{
|
|
10
|
-
format: z.ZodLiteral<"enhance-capture">;
|
|
11
|
-
version: z.ZodLiteral<1>;
|
|
12
|
-
key: z.ZodObject<{
|
|
13
|
-
source: z.ZodString;
|
|
14
|
-
journey: z.ZodString;
|
|
15
|
-
step: z.ZodString;
|
|
16
|
-
variant: z.ZodString;
|
|
17
|
-
}, z.core.$strict>;
|
|
18
|
-
label: z.ZodString;
|
|
19
|
-
journeyLabel: z.ZodString;
|
|
20
|
-
order: z.ZodNumber;
|
|
21
|
-
viewport: z.ZodObject<{
|
|
22
|
-
width: z.ZodNumber;
|
|
23
|
-
height: z.ZodNumber;
|
|
24
|
-
deviceScaleFactor: z.ZodNumber;
|
|
25
|
-
}, z.core.$strict>;
|
|
26
|
-
extent: z.ZodEnum<{
|
|
27
|
-
viewport: "viewport";
|
|
28
|
-
"full-page": "full-page";
|
|
29
|
-
}>;
|
|
30
|
-
source: z.ZodObject<{
|
|
31
|
-
format: z.ZodLiteral<"rrweb-screen">;
|
|
32
|
-
version: z.ZodLiteral<1>;
|
|
33
|
-
blob: z.ZodObject<{
|
|
34
|
-
sha256: z.ZodString;
|
|
35
|
-
bytes: z.ZodNumber;
|
|
36
|
-
mediaType: z.ZodString;
|
|
37
|
-
}, z.core.$strict>;
|
|
38
|
-
}, z.core.$strict>;
|
|
39
|
-
preview: z.ZodObject<{
|
|
40
|
-
blob: z.ZodObject<{
|
|
41
|
-
sha256: z.ZodString;
|
|
42
|
-
bytes: z.ZodNumber;
|
|
43
|
-
mediaType: z.ZodString;
|
|
44
|
-
}, z.core.$strict>;
|
|
45
|
-
width: z.ZodNumber;
|
|
46
|
-
height: z.ZodNumber;
|
|
47
|
-
pixelRatio: z.ZodNumber;
|
|
48
|
-
}, z.core.$strict>;
|
|
49
|
-
assets: z.ZodArray<z.ZodObject<{
|
|
50
|
-
url: z.ZodURL;
|
|
51
|
-
blob: z.ZodObject<{
|
|
52
|
-
sha256: z.ZodString;
|
|
53
|
-
bytes: z.ZodNumber;
|
|
54
|
-
mediaType: z.ZodString;
|
|
55
|
-
}, z.core.$strict>;
|
|
56
|
-
}, z.core.$strict>>;
|
|
57
|
-
provenance: z.ZodObject<{
|
|
58
|
-
adapter: z.ZodString;
|
|
59
|
-
sdkVersion: z.ZodString;
|
|
60
|
-
kernelVersion: z.ZodString;
|
|
61
|
-
browser: z.ZodString;
|
|
62
|
-
capturedAt: z.ZodISODateTime;
|
|
63
|
-
sourceUrl: z.ZodOptional<z.ZodURL>;
|
|
64
|
-
commit: z.ZodOptional<z.ZodString>;
|
|
65
|
-
}, z.core.$strict>;
|
|
66
|
-
issues: z.ZodArray<z.ZodObject<{
|
|
67
|
-
code: z.ZodString;
|
|
68
|
-
message: z.ZodString;
|
|
69
|
-
}, z.core.$strict>>;
|
|
70
|
-
}, z.core.$strict>;
|
|
71
|
-
type CaptureArtifact = z.infer<typeof captureArtifactSchema>;
|
|
72
|
-
declare const captureRunDescriptorSchema: z.ZodObject<{
|
|
73
|
-
id: z.ZodUUID;
|
|
74
|
-
canvasId: z.ZodUUID;
|
|
75
|
-
source: z.ZodString;
|
|
76
|
-
runKey: z.ZodString;
|
|
77
|
-
generation: z.ZodNumber;
|
|
78
|
-
participants: z.ZodArray<z.ZodString>;
|
|
79
|
-
expiresAt: z.ZodISODateTime;
|
|
80
|
-
formatVersion: z.ZodLiteral<1>;
|
|
81
|
-
}, z.core.$strict>;
|
|
82
|
-
type CaptureRunDescriptor = z.infer<typeof captureRunDescriptorSchema>;
|
|
83
|
-
declare const captureManifestSchema: z.ZodObject<{
|
|
84
|
-
format: z.ZodLiteral<"enhance-capture-run">;
|
|
85
|
-
version: z.ZodLiteral<1>;
|
|
86
|
-
run: z.ZodObject<{
|
|
87
|
-
id: z.ZodUUID;
|
|
88
|
-
canvasId: z.ZodUUID;
|
|
89
|
-
source: z.ZodString;
|
|
90
|
-
runKey: z.ZodString;
|
|
91
|
-
generation: z.ZodNumber;
|
|
92
|
-
participants: z.ZodArray<z.ZodString>;
|
|
93
|
-
expiresAt: z.ZodISODateTime;
|
|
94
|
-
formatVersion: z.ZodLiteral<1>;
|
|
95
|
-
}, z.core.$strict>;
|
|
96
|
-
participants: z.ZodArray<z.ZodObject<{
|
|
97
|
-
id: z.ZodString;
|
|
98
|
-
status: z.ZodEnum<{
|
|
99
|
-
passed: "passed";
|
|
100
|
-
failed: "failed";
|
|
101
|
-
interrupted: "interrupted";
|
|
102
|
-
}>;
|
|
103
|
-
}, z.core.$strict>>;
|
|
104
|
-
attempts: z.ZodArray<z.ZodObject<{
|
|
105
|
-
participant: z.ZodString;
|
|
106
|
-
testId: z.ZodString;
|
|
107
|
-
project: z.ZodString;
|
|
108
|
-
retry: z.ZodNumber;
|
|
109
|
-
status: z.ZodEnum<{
|
|
110
|
-
passed: "passed";
|
|
111
|
-
failed: "failed";
|
|
112
|
-
interrupted: "interrupted";
|
|
113
|
-
skipped: "skipped";
|
|
114
|
-
timedOut: "timedOut";
|
|
115
|
-
}>;
|
|
116
|
-
captures: z.ZodArray<z.ZodObject<{
|
|
117
|
-
format: z.ZodLiteral<"enhance-capture">;
|
|
118
|
-
version: z.ZodLiteral<1>;
|
|
119
|
-
key: z.ZodObject<{
|
|
120
|
-
source: z.ZodString;
|
|
121
|
-
journey: z.ZodString;
|
|
122
|
-
step: z.ZodString;
|
|
123
|
-
variant: z.ZodString;
|
|
124
|
-
}, z.core.$strict>;
|
|
125
|
-
label: z.ZodString;
|
|
126
|
-
journeyLabel: z.ZodString;
|
|
127
|
-
order: z.ZodNumber;
|
|
128
|
-
viewport: z.ZodObject<{
|
|
129
|
-
width: z.ZodNumber;
|
|
130
|
-
height: z.ZodNumber;
|
|
131
|
-
deviceScaleFactor: z.ZodNumber;
|
|
132
|
-
}, z.core.$strict>;
|
|
133
|
-
extent: z.ZodEnum<{
|
|
134
|
-
viewport: "viewport";
|
|
135
|
-
"full-page": "full-page";
|
|
136
|
-
}>;
|
|
137
|
-
source: z.ZodObject<{
|
|
138
|
-
format: z.ZodLiteral<"rrweb-screen">;
|
|
139
|
-
version: z.ZodLiteral<1>;
|
|
140
|
-
blob: z.ZodObject<{
|
|
141
|
-
sha256: z.ZodString;
|
|
142
|
-
bytes: z.ZodNumber;
|
|
143
|
-
mediaType: z.ZodString;
|
|
144
|
-
}, z.core.$strict>;
|
|
145
|
-
}, z.core.$strict>;
|
|
146
|
-
preview: z.ZodObject<{
|
|
147
|
-
blob: z.ZodObject<{
|
|
148
|
-
sha256: z.ZodString;
|
|
149
|
-
bytes: z.ZodNumber;
|
|
150
|
-
mediaType: z.ZodString;
|
|
151
|
-
}, z.core.$strict>;
|
|
152
|
-
width: z.ZodNumber;
|
|
153
|
-
height: z.ZodNumber;
|
|
154
|
-
pixelRatio: z.ZodNumber;
|
|
155
|
-
}, z.core.$strict>;
|
|
156
|
-
assets: z.ZodArray<z.ZodObject<{
|
|
157
|
-
url: z.ZodURL;
|
|
158
|
-
blob: z.ZodObject<{
|
|
159
|
-
sha256: z.ZodString;
|
|
160
|
-
bytes: z.ZodNumber;
|
|
161
|
-
mediaType: z.ZodString;
|
|
162
|
-
}, z.core.$strict>;
|
|
163
|
-
}, z.core.$strict>>;
|
|
164
|
-
provenance: z.ZodObject<{
|
|
165
|
-
adapter: z.ZodString;
|
|
166
|
-
sdkVersion: z.ZodString;
|
|
167
|
-
kernelVersion: z.ZodString;
|
|
168
|
-
browser: z.ZodString;
|
|
169
|
-
capturedAt: z.ZodISODateTime;
|
|
170
|
-
sourceUrl: z.ZodOptional<z.ZodURL>;
|
|
171
|
-
commit: z.ZodOptional<z.ZodString>;
|
|
172
|
-
}, z.core.$strict>;
|
|
173
|
-
issues: z.ZodArray<z.ZodObject<{
|
|
174
|
-
code: z.ZodString;
|
|
175
|
-
message: z.ZodString;
|
|
176
|
-
}, z.core.$strict>>;
|
|
177
|
-
}, z.core.$strict>>;
|
|
178
|
-
}, z.core.$strict>>;
|
|
179
|
-
ordering: z.ZodEnum<{
|
|
180
|
-
partial: "partial";
|
|
181
|
-
complete: "complete";
|
|
182
|
-
}>;
|
|
183
|
-
}, z.core.$strict>;
|
|
184
|
-
type CaptureManifest = z.infer<typeof captureManifestSchema>;
|
|
185
|
-
declare const captureReceiptSchema: z.ZodObject<{
|
|
186
|
-
runId: z.ZodUUID;
|
|
187
|
-
canvasId: z.ZodUUID;
|
|
188
|
-
canvasUrl: z.ZodURL;
|
|
189
|
-
version: z.ZodNumber;
|
|
190
|
-
manifestDigest: z.ZodString;
|
|
191
|
-
frames: z.ZodArray<z.ZodObject<{
|
|
192
|
-
key: z.ZodObject<{
|
|
193
|
-
source: z.ZodString;
|
|
194
|
-
journey: z.ZodString;
|
|
195
|
-
step: z.ZodString;
|
|
196
|
-
variant: z.ZodString;
|
|
197
|
-
}, z.core.$strict>;
|
|
198
|
-
frameId: z.ZodString;
|
|
199
|
-
captureId: z.ZodUUID;
|
|
200
|
-
}, z.core.$strict>>;
|
|
201
|
-
issues: z.ZodArray<z.ZodObject<{
|
|
202
|
-
code: z.ZodString;
|
|
203
|
-
message: z.ZodString;
|
|
204
|
-
}, z.core.$strict>>;
|
|
205
|
-
}, z.core.$strict>;
|
|
206
|
-
type CaptureReceipt = z.infer<typeof captureReceiptSchema>;
|
|
207
|
-
declare const getCaptureRunOutputSchema: z.ZodObject<{
|
|
208
|
-
run: z.ZodObject<{
|
|
209
|
-
id: z.ZodUUID;
|
|
210
|
-
canvasId: z.ZodUUID;
|
|
211
|
-
source: z.ZodString;
|
|
212
|
-
runKey: z.ZodString;
|
|
213
|
-
generation: z.ZodNumber;
|
|
214
|
-
participants: z.ZodArray<z.ZodString>;
|
|
215
|
-
expiresAt: z.ZodISODateTime;
|
|
216
|
-
formatVersion: z.ZodLiteral<1>;
|
|
217
|
-
}, z.core.$strict>;
|
|
218
|
-
state: z.ZodEnum<{
|
|
219
|
-
failed: "failed";
|
|
220
|
-
collecting: "collecting";
|
|
221
|
-
sealed: "sealed";
|
|
222
|
-
converting: "converting";
|
|
223
|
-
committed: "committed";
|
|
224
|
-
cancelled: "cancelled";
|
|
225
|
-
}>;
|
|
226
|
-
receipt: z.ZodNullable<z.ZodObject<{
|
|
227
|
-
runId: z.ZodUUID;
|
|
228
|
-
canvasId: z.ZodUUID;
|
|
229
|
-
canvasUrl: z.ZodURL;
|
|
230
|
-
version: z.ZodNumber;
|
|
231
|
-
manifestDigest: z.ZodString;
|
|
232
|
-
frames: z.ZodArray<z.ZodObject<{
|
|
233
|
-
key: z.ZodObject<{
|
|
234
|
-
source: z.ZodString;
|
|
235
|
-
journey: z.ZodString;
|
|
236
|
-
step: z.ZodString;
|
|
237
|
-
variant: z.ZodString;
|
|
238
|
-
}, z.core.$strict>;
|
|
239
|
-
frameId: z.ZodString;
|
|
240
|
-
captureId: z.ZodUUID;
|
|
241
|
-
}, z.core.$strict>>;
|
|
242
|
-
issues: z.ZodArray<z.ZodObject<{
|
|
243
|
-
code: z.ZodString;
|
|
244
|
-
message: z.ZodString;
|
|
245
|
-
}, z.core.$strict>>;
|
|
246
|
-
}, z.core.$strict>>;
|
|
247
|
-
failure: z.ZodNullable<z.ZodObject<{
|
|
248
|
-
code: z.ZodString;
|
|
249
|
-
message: z.ZodString;
|
|
250
|
-
}, z.core.$strict>>;
|
|
251
|
-
}, z.core.$strict>;
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region ../contract/src/capture/capture-manifest.lib.d.ts
|
|
254
|
-
/** All publishers select whole terminal attempts with the same completeness rules. */
|
|
255
|
-
declare const selectedCaptures: (input: CaptureManifest) => readonly CaptureArtifact[] | string;
|
|
256
|
-
//#endregion
|
|
257
|
-
//#region src/node/capture-files.lib.d.ts
|
|
258
|
-
interface CapturePayload {
|
|
259
|
-
readonly artifact: CaptureArtifact;
|
|
260
|
-
readonly blobs: readonly {
|
|
261
|
-
readonly description: CaptureBlob;
|
|
262
|
-
readonly bytes: Uint8Array;
|
|
263
|
-
}[];
|
|
264
|
-
}
|
|
265
|
-
//#endregion
|
|
266
|
-
export { CaptureReceipt as a, captureManifestSchema as c, CaptureManifest as i, getCaptureRunOutputSchema as l, selectedCaptures as n, CaptureRunDescriptor as o, CaptureArtifact as r, captureArtifactSchema as s, CapturePayload as t };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { s as captureError } from "./capture-files.lib-BA_KBz9W.mjs";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
//#region src/playwright/environment.config.ts
|
|
4
|
-
const captureEnvironment = () => ({ directory: process.env["ENHANCE_CAPTURE_DIRECTORY"] ?? "" });
|
|
5
|
-
const setCaptureDirectory = (directory) => {
|
|
6
|
-
if (directory === "") throw captureError("configuration", "Capture output directory must not be empty.");
|
|
7
|
-
process.env["ENHANCE_CAPTURE_DIRECTORY"] = directory;
|
|
8
|
-
};
|
|
9
|
-
//#endregion
|
|
10
|
-
export { setCaptureDirectory as n, captureEnvironment as t };
|