@riddledc/riddle-proof 0.8.85 → 0.8.87
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/dist/advanced/index.d.cts +1 -1
- package/dist/advanced/index.d.ts +1 -1
- package/dist/advanced/proof-run-engine.d.cts +1 -1
- package/dist/advanced/proof-run-engine.d.ts +1 -1
- package/dist/change-proof.cjs +2 -9
- package/dist/change-proof.d.cts +1 -1
- package/dist/change-proof.d.ts +1 -1
- package/dist/change-proof.js +2 -2
- package/dist/{chunk-AFARUBE4.js → chunk-3W4NGKZ6.js} +11 -11
- package/dist/chunk-6S33FQL7.js +14 -0
- package/dist/{chunk-FW7CKARF.js → chunk-7W6ZJPHJ.js} +1 -1
- package/dist/{chunk-JZKLCY5G.js → chunk-BVYM4WJ5.js} +1 -1
- package/dist/chunk-GQOE5Q7C.js +32 -0
- package/dist/chunk-H5AALGSA.js +32 -0
- package/dist/{chunk-2K3DIK7A.js → chunk-KF6F2RMQ.js} +301 -3979
- package/dist/{chunk-O2AO726C.js → chunk-NR2XQXIC.js} +3 -3
- package/dist/cli/index.js +5 -5
- package/dist/cli.cjs +285 -3999
- package/dist/cli.js +5 -5
- package/dist/evidence-trust-root.cjs +54 -0
- package/dist/evidence-trust-root.d.cts +2 -0
- package/dist/evidence-trust-root.d.ts +2 -0
- package/dist/evidence-trust-root.js +31 -0
- package/dist/index.cjs +346 -3991
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +80 -14
- package/dist/packet.cjs +54 -0
- package/dist/packet.d.cts +2 -0
- package/dist/packet.d.ts +2 -0
- package/dist/packet.js +31 -0
- package/dist/pr-comment.cjs +2 -9
- package/dist/pr-comment.d.cts +2 -2
- package/dist/pr-comment.d.ts +2 -2
- package/dist/pr-comment.js +3 -3
- package/dist/profile/index.cjs +277 -3991
- package/dist/profile/index.d.cts +2 -3
- package/dist/profile/index.d.ts +2 -3
- package/dist/profile/index.js +1 -1
- package/dist/profile-suggestions.cjs +2 -2
- package/dist/profile-suggestions.d.cts +1 -3
- package/dist/profile-suggestions.d.ts +1 -3
- package/dist/profile-suggestions.js +2 -2
- package/dist/profile.cjs +277 -3991
- package/dist/profile.d.cts +3 -550
- package/dist/profile.d.ts +3 -550
- package/dist/profile.js +1 -1
- package/dist/{proof-run-engine-DpChFR5H.d.cts → proof-run-engine-Baiv6l3A.d.cts} +3 -3
- package/dist/{proof-run-engine-BqRoA3Do.d.ts → proof-run-engine-MiKZt9oY.d.ts} +3 -3
- package/dist/proof-run-engine.d.cts +1 -1
- package/dist/proof-run-engine.d.ts +1 -1
- package/dist/receipts.d.cts +3 -0
- package/dist/receipts.d.ts +3 -0
- package/dist/rule-trust-root.cjs +36 -0
- package/dist/rule-trust-root.d.cts +2 -0
- package/dist/rule-trust-root.d.ts +2 -0
- package/dist/rule-trust-root.js +13 -0
- package/package.json +20 -5
|
@@ -1,143 +1,44 @@
|
|
|
1
1
|
// src/profile.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"no_mobile_horizontal_overflow",
|
|
43
|
-
"no_fatal_console_errors",
|
|
44
|
-
"no_console_warnings"
|
|
45
|
-
];
|
|
46
|
-
var RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES = [
|
|
47
|
-
"click",
|
|
48
|
-
"tap",
|
|
49
|
-
"tap_until",
|
|
50
|
-
"drag",
|
|
51
|
-
"press",
|
|
52
|
-
"key_down",
|
|
53
|
-
"key_up",
|
|
54
|
-
"fill",
|
|
55
|
-
"set_input_value",
|
|
56
|
-
"set_range_value",
|
|
57
|
-
"deterministic_runtime",
|
|
58
|
-
"canvas_signature",
|
|
59
|
-
"assert_text_visible",
|
|
60
|
-
"assert_text_absent",
|
|
61
|
-
"assert_selector_count",
|
|
62
|
-
"assert_window_value",
|
|
63
|
-
"assert_window_number",
|
|
64
|
-
"local_storage",
|
|
65
|
-
"session_storage",
|
|
66
|
-
"clear_storage",
|
|
67
|
-
"clear_console",
|
|
68
|
-
"dialog_response",
|
|
69
|
-
"screenshot",
|
|
70
|
-
"wait",
|
|
71
|
-
"wait_for_selector",
|
|
72
|
-
"wait_for_text",
|
|
73
|
-
"window_eval",
|
|
74
|
-
"window_call",
|
|
75
|
-
"window_call_until"
|
|
76
|
-
];
|
|
77
|
-
var RIDDLE_PROOF_PROFILE_NETWORK_ABORT_ERROR_CODES = [
|
|
78
|
-
"aborted",
|
|
79
|
-
"accessdenied",
|
|
80
|
-
"addressunreachable",
|
|
81
|
-
"blockedbyclient",
|
|
82
|
-
"blockedbyresponse",
|
|
83
|
-
"connectionaborted",
|
|
84
|
-
"connectionclosed",
|
|
85
|
-
"connectionfailed",
|
|
86
|
-
"connectionrefused",
|
|
87
|
-
"connectionreset",
|
|
88
|
-
"internetdisconnected",
|
|
89
|
-
"namenotresolved",
|
|
90
|
-
"timedout",
|
|
91
|
-
"failed"
|
|
92
|
-
];
|
|
93
|
-
var RIDDLE_PROOF_ORDERED_TRACE_OPERATORS = [
|
|
94
|
-
"exists",
|
|
95
|
-
"equals",
|
|
96
|
-
"not_equals",
|
|
97
|
-
"truthy",
|
|
98
|
-
"falsy",
|
|
99
|
-
"gt",
|
|
100
|
-
"gte",
|
|
101
|
-
"lt",
|
|
102
|
-
"lte",
|
|
103
|
-
"abs_gt",
|
|
104
|
-
"abs_gte",
|
|
105
|
-
"abs_lt",
|
|
106
|
-
"abs_lte"
|
|
107
|
-
];
|
|
108
|
-
function uniqueNonEmptyStrings(values) {
|
|
109
|
-
const seen = /* @__PURE__ */ new Set();
|
|
110
|
-
const result = [];
|
|
111
|
-
for (const value of values ?? []) {
|
|
112
|
-
const normalized = typeof value === "string" ? value.trim() : "";
|
|
113
|
-
if (!normalized || seen.has(normalized)) continue;
|
|
114
|
-
seen.add(normalized);
|
|
115
|
-
result.push(normalized);
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
function deriveRiddleProofArtifactBodyAssertions(input) {
|
|
120
|
-
const artifactText = typeof input.artifact_text === "string" ? input.artifact_text : "";
|
|
121
|
-
const candidates = uniqueNonEmptyStrings(input.candidates);
|
|
122
|
-
const required = uniqueNonEmptyStrings(input.required);
|
|
123
|
-
const mergedCandidates = uniqueNonEmptyStrings([...required, ...candidates]);
|
|
124
|
-
const presentCandidates = mergedCandidates.filter((snippet) => artifactText.includes(snippet));
|
|
125
|
-
const missingCandidates = mergedCandidates.filter((snippet) => !artifactText.includes(snippet));
|
|
126
|
-
const missingRequired = required.filter((snippet) => !artifactText.includes(snippet));
|
|
127
|
-
const warnings = missingCandidates.map((snippet) => `candidate snippet is not present in artifact body: ${snippet}`);
|
|
128
|
-
return {
|
|
129
|
-
version: "riddle-proof.artifact-body-assertions.v1",
|
|
130
|
-
ok: missingRequired.length === 0,
|
|
131
|
-
body_contains: presentCandidates,
|
|
132
|
-
present_candidates: presentCandidates,
|
|
133
|
-
missing_candidates: missingCandidates,
|
|
134
|
-
missing_required: missingRequired,
|
|
135
|
-
warnings
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
var DEFAULT_VIEWPORTS = [
|
|
139
|
-
{ name: "desktop", width: 1280, height: 800 }
|
|
140
|
-
];
|
|
2
|
+
import {
|
|
3
|
+
RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS,
|
|
4
|
+
RIDDLE_PROOF_ORDERED_TRACE_OPERATORS,
|
|
5
|
+
RIDDLE_PROOF_PROFILE_CHECK_TYPES,
|
|
6
|
+
RIDDLE_PROOF_PROFILE_EVIDENCE_VERSION,
|
|
7
|
+
RIDDLE_PROOF_PROFILE_NETWORK_ABORT_ERROR_CODES,
|
|
8
|
+
RIDDLE_PROOF_PROFILE_RESULT_VERSION,
|
|
9
|
+
RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES,
|
|
10
|
+
RIDDLE_PROOF_PROFILE_STATUSES,
|
|
11
|
+
RIDDLE_PROOF_PROFILE_VERSION,
|
|
12
|
+
applyRiddleProofProfileArtifactCompleteness,
|
|
13
|
+
assessRiddleProofOrderedTrace as assessRiddleProofOrderedTrace2,
|
|
14
|
+
assessRiddleProofOrderedTraceSetupResults as assessRiddleProofOrderedTraceSetupResults2,
|
|
15
|
+
assessRiddleProofProfileArtifactCompleteness,
|
|
16
|
+
assessRiddleProofProfileEvidence,
|
|
17
|
+
collectRiddleProfileArtifactRefs,
|
|
18
|
+
collectRiddleProofProfileWarnings as collectRiddleProofProfileWarnings2,
|
|
19
|
+
createRiddleProofProfileConfigurationError,
|
|
20
|
+
createRiddleProofProfileEnvironmentBlockedResult,
|
|
21
|
+
createRiddleProofProfileInsufficientResult,
|
|
22
|
+
deriveRiddleProofArtifactBodyAssertions,
|
|
23
|
+
extractRiddleProofProfileResult,
|
|
24
|
+
normalizeRiddleProofProfile,
|
|
25
|
+
preflightRiddleProofProfileRunnerArtifacts,
|
|
26
|
+
profileStatusExitCode,
|
|
27
|
+
resolveRiddleProofProfileRouteUrl,
|
|
28
|
+
resolveRiddleProofProfileTargetUrl as resolveRiddleProofProfileTargetUrl2,
|
|
29
|
+
resolveRiddleProofProfileTimeoutSec,
|
|
30
|
+
slugifyRiddleProofProfileName as slugifyRiddleProofProfileName2,
|
|
31
|
+
summarizeRiddleProofProfileResult
|
|
32
|
+
} from "@riddledc/riddle-proof-core/profile";
|
|
33
|
+
|
|
34
|
+
// src/profile-capabilities.ts
|
|
35
|
+
import {
|
|
36
|
+
assessRiddleProofOrderedTrace,
|
|
37
|
+
assessRiddleProofOrderedTraceSetupResults,
|
|
38
|
+
collectRiddleProofProfileWarnings,
|
|
39
|
+
resolveRiddleProofProfileTargetUrl,
|
|
40
|
+
slugifyRiddleProofProfileName
|
|
41
|
+
} from "@riddledc/riddle-proof-core/profile";
|
|
141
42
|
function isRecord(value) {
|
|
142
43
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
143
44
|
}
|
|
@@ -147,113 +48,12 @@ function stringValue(value) {
|
|
|
147
48
|
function hasOwn(value, key) {
|
|
148
49
|
return Object.prototype.hasOwnProperty.call(value, key);
|
|
149
50
|
}
|
|
150
|
-
function stringFromOwn(input, ...keys) {
|
|
151
|
-
for (const key of keys) {
|
|
152
|
-
if (hasOwn(input, key)) {
|
|
153
|
-
const value = input[key];
|
|
154
|
-
if (value !== void 0 && value !== null) return String(value);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return void 0;
|
|
158
|
-
}
|
|
159
|
-
function valueFromOwn(input, ...keys) {
|
|
160
|
-
for (const key of keys) {
|
|
161
|
-
if (hasOwn(input, key)) return input[key];
|
|
162
|
-
}
|
|
163
|
-
return void 0;
|
|
164
|
-
}
|
|
165
51
|
function numberValue(value) {
|
|
166
52
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
167
53
|
}
|
|
168
54
|
function booleanValue(value) {
|
|
169
55
|
return typeof value === "boolean" ? value : void 0;
|
|
170
56
|
}
|
|
171
|
-
function horizontalBoundsOverflowPx(value) {
|
|
172
|
-
if (!isRecord(value)) return 0;
|
|
173
|
-
let max = maxPositiveNumber(
|
|
174
|
-
value.overflow_px,
|
|
175
|
-
value.overflow,
|
|
176
|
-
value.bounds_overflow_px,
|
|
177
|
-
value.horizontal_overflow_px,
|
|
178
|
-
value.left_overflow_px,
|
|
179
|
-
value.right_overflow_px
|
|
180
|
-
);
|
|
181
|
-
for (const offender of boundsOffendersForEvidence(value)) {
|
|
182
|
-
max = Math.max(max, horizontalOffenderOverflowPx(offender));
|
|
183
|
-
}
|
|
184
|
-
return roundPixels(max);
|
|
185
|
-
}
|
|
186
|
-
function horizontalOffenderOverflowPx(value) {
|
|
187
|
-
if (!isRecord(value)) return 0;
|
|
188
|
-
let max = maxPositiveNumber(
|
|
189
|
-
value.overflow,
|
|
190
|
-
value.overflow_px,
|
|
191
|
-
value.bounds_overflow_px,
|
|
192
|
-
value.horizontal_overflow_px,
|
|
193
|
-
value.left_overflow_px,
|
|
194
|
-
value.right_overflow_px,
|
|
195
|
-
value.leftOverflowPx,
|
|
196
|
-
value.rightOverflowPx
|
|
197
|
-
);
|
|
198
|
-
const clipped = isRecord(value.clipped || value.clip || value.clipping) ? value.clipped || value.clip || value.clipping : void 0;
|
|
199
|
-
if (isRecord(clipped)) {
|
|
200
|
-
max = Math.max(max, maxPositiveNumber(
|
|
201
|
-
clipped.left,
|
|
202
|
-
clipped.right,
|
|
203
|
-
clipped.left_px,
|
|
204
|
-
clipped.right_px,
|
|
205
|
-
clipped.leftPx,
|
|
206
|
-
clipped.rightPx
|
|
207
|
-
));
|
|
208
|
-
}
|
|
209
|
-
const rect = isRecord(value.rect || value.bounds || value.bounding_rect || value.boundingRect) ? value.rect || value.bounds || value.bounding_rect || value.boundingRect : void 0;
|
|
210
|
-
const viewportWidth = numberValue(value.viewport_width ?? value.viewportWidth);
|
|
211
|
-
if (isRecord(rect) && viewportWidth !== void 0) {
|
|
212
|
-
const left = numberValue(rect.left);
|
|
213
|
-
const right = numberValue(rect.right);
|
|
214
|
-
if (left !== void 0 && left < 0) max = Math.max(max, Math.abs(left));
|
|
215
|
-
if (right !== void 0 && right > viewportWidth) max = Math.max(max, right - viewportWidth);
|
|
216
|
-
}
|
|
217
|
-
return roundPixels(max);
|
|
218
|
-
}
|
|
219
|
-
function boundsOffendersForEvidence(value) {
|
|
220
|
-
if (!isRecord(value)) return [];
|
|
221
|
-
const offenders = [
|
|
222
|
-
...Array.isArray(value.overflow_offenders) ? value.overflow_offenders : [],
|
|
223
|
-
...Array.isArray(value.overflowOffenders) ? value.overflowOffenders : [],
|
|
224
|
-
...Array.isArray(value.bounds_offenders) ? value.bounds_offenders : [],
|
|
225
|
-
...Array.isArray(value.boundsOffenders) ? value.boundsOffenders : [],
|
|
226
|
-
...Array.isArray(value.clipped_elements) ? value.clipped_elements : [],
|
|
227
|
-
...Array.isArray(value.clippedElements) ? value.clippedElements : [],
|
|
228
|
-
...Array.isArray(value.clipping_offenders) ? value.clipping_offenders : [],
|
|
229
|
-
...Array.isArray(value.clippingOffenders) ? value.clippingOffenders : []
|
|
230
|
-
];
|
|
231
|
-
return offenders.filter((item) => isRecord(item)).sort((a, b) => horizontalOffenderOverflowPx(b) - horizontalOffenderOverflowPx(a));
|
|
232
|
-
}
|
|
233
|
-
function maxPositiveNumber(...values) {
|
|
234
|
-
let max = 0;
|
|
235
|
-
for (const value of values) {
|
|
236
|
-
const number = numberValue(value);
|
|
237
|
-
if (number !== void 0 && number > max) max = number;
|
|
238
|
-
}
|
|
239
|
-
return max;
|
|
240
|
-
}
|
|
241
|
-
function roundPixels(value) {
|
|
242
|
-
return Math.round(value * 100) / 100;
|
|
243
|
-
}
|
|
244
|
-
function timeoutSecValue(value) {
|
|
245
|
-
const number = numberValue(value);
|
|
246
|
-
return number && number > 0 ? Math.ceil(number) : void 0;
|
|
247
|
-
}
|
|
248
|
-
function jsonRecord(value) {
|
|
249
|
-
if (!isRecord(value)) return void 0;
|
|
250
|
-
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toJsonValue(child)]));
|
|
251
|
-
}
|
|
252
|
-
function stringRecord(value) {
|
|
253
|
-
if (!isRecord(value)) return void 0;
|
|
254
|
-
const entries = Object.entries(value).map(([key, child]) => [key, String(child)]).filter(([key]) => key.trim());
|
|
255
|
-
return entries.length ? Object.fromEntries(entries) : void 0;
|
|
256
|
-
}
|
|
257
57
|
function toJsonValue(value) {
|
|
258
58
|
if (value === null || value === void 0) return null;
|
|
259
59
|
if (typeof value === "string" || typeof value === "boolean") return value;
|
|
@@ -396,185 +196,6 @@ function resolveJsonPath(root, path) {
|
|
|
396
196
|
}
|
|
397
197
|
return { exists: true, value: current };
|
|
398
198
|
}
|
|
399
|
-
function assessRiddleProofOrderedTrace(trace, events) {
|
|
400
|
-
const insufficient = (reason, traceLength = Array.isArray(trace) ? trace.length : 0, witnesses2 = [], missingEvent, missingPaths) => ({
|
|
401
|
-
version: "riddle-proof.ordered-trace-assessment.v1",
|
|
402
|
-
status: "proof_insufficient",
|
|
403
|
-
trace_length: traceLength,
|
|
404
|
-
witnesses: witnesses2,
|
|
405
|
-
missing_event: missingEvent,
|
|
406
|
-
missing_paths: missingPaths,
|
|
407
|
-
reason
|
|
408
|
-
});
|
|
409
|
-
const parsePath = (path) => {
|
|
410
|
-
const segments = [];
|
|
411
|
-
let token = "";
|
|
412
|
-
const pushToken = () => {
|
|
413
|
-
const value = token.trim();
|
|
414
|
-
if (value) segments.push(value);
|
|
415
|
-
token = "";
|
|
416
|
-
};
|
|
417
|
-
for (let index = 0; index < path.length; index += 1) {
|
|
418
|
-
const char = path[index];
|
|
419
|
-
if (char === ".") {
|
|
420
|
-
pushToken();
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
if (char !== "[") {
|
|
424
|
-
token += char;
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
pushToken();
|
|
428
|
-
const closeIndex = path.indexOf("]", index + 1);
|
|
429
|
-
if (closeIndex === -1) throw new Error(`unterminated bracket at ${index}`);
|
|
430
|
-
const bracket = path.slice(index + 1, closeIndex).trim();
|
|
431
|
-
if (!bracket) throw new Error(`empty bracket at ${index}`);
|
|
432
|
-
if (/^\d+$/.test(bracket)) {
|
|
433
|
-
segments.push(Number(bracket));
|
|
434
|
-
} else {
|
|
435
|
-
segments.push(bracket.replace(/^['"]|['"]$/g, ""));
|
|
436
|
-
}
|
|
437
|
-
index = closeIndex;
|
|
438
|
-
}
|
|
439
|
-
pushToken();
|
|
440
|
-
return segments;
|
|
441
|
-
};
|
|
442
|
-
const resolve = (root, path) => {
|
|
443
|
-
let segments;
|
|
444
|
-
try {
|
|
445
|
-
segments = parsePath(path);
|
|
446
|
-
} catch {
|
|
447
|
-
return { exists: false };
|
|
448
|
-
}
|
|
449
|
-
let current = root;
|
|
450
|
-
for (const segment of segments) {
|
|
451
|
-
if (Array.isArray(current)) {
|
|
452
|
-
const index = typeof segment === "number" ? segment : /^\d+$/.test(segment) ? Number(segment) : -1;
|
|
453
|
-
if (index < 0 || index >= current.length) return { exists: false };
|
|
454
|
-
current = current[index];
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
if (typeof segment !== "string" || current === null || typeof current !== "object") return { exists: false };
|
|
458
|
-
if (!Object.hasOwn(current, segment)) return { exists: false };
|
|
459
|
-
current = current[segment];
|
|
460
|
-
}
|
|
461
|
-
return { exists: true, value: current };
|
|
462
|
-
};
|
|
463
|
-
const valuesEqual = (left, right) => {
|
|
464
|
-
if (Object.is(left, right)) return true;
|
|
465
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
466
|
-
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => valuesEqual(value, right[index]));
|
|
467
|
-
}
|
|
468
|
-
if (left === null || right === null || typeof left !== "object" || typeof right !== "object") return false;
|
|
469
|
-
const leftRecord = left;
|
|
470
|
-
const rightRecord = right;
|
|
471
|
-
const leftKeys = Object.keys(leftRecord).sort();
|
|
472
|
-
const rightKeys = Object.keys(rightRecord).sort();
|
|
473
|
-
return leftKeys.length === rightKeys.length && leftKeys.every((key, index) => key === rightKeys[index] && valuesEqual(leftRecord[key], rightRecord[key]));
|
|
474
|
-
};
|
|
475
|
-
const numericOperator = (op) => [
|
|
476
|
-
"gt",
|
|
477
|
-
"gte",
|
|
478
|
-
"lt",
|
|
479
|
-
"lte",
|
|
480
|
-
"abs_gt",
|
|
481
|
-
"abs_gte",
|
|
482
|
-
"abs_lt",
|
|
483
|
-
"abs_lte"
|
|
484
|
-
].includes(op);
|
|
485
|
-
const matches = (value, predicate) => {
|
|
486
|
-
if (predicate.op === "exists") return true;
|
|
487
|
-
if (predicate.op === "equals") return valuesEqual(value, predicate.value);
|
|
488
|
-
if (predicate.op === "not_equals") return !valuesEqual(value, predicate.value);
|
|
489
|
-
if (predicate.op === "truthy") return Boolean(value);
|
|
490
|
-
if (predicate.op === "falsy") return !value;
|
|
491
|
-
const observed = typeof value === "number" ? value : Number.NaN;
|
|
492
|
-
const expected = typeof predicate.value === "number" ? predicate.value : Number.NaN;
|
|
493
|
-
if (!Number.isFinite(observed) || !Number.isFinite(expected)) return false;
|
|
494
|
-
const candidate = predicate.op.startsWith("abs_") ? Math.abs(observed) : observed;
|
|
495
|
-
if (predicate.op === "gt" || predicate.op === "abs_gt") return candidate > expected;
|
|
496
|
-
if (predicate.op === "gte" || predicate.op === "abs_gte") return candidate >= expected;
|
|
497
|
-
if (predicate.op === "lt" || predicate.op === "abs_lt") return candidate < expected;
|
|
498
|
-
return candidate <= expected;
|
|
499
|
-
};
|
|
500
|
-
if (!Array.isArray(trace) || trace.length === 0) return insufficient("trace_missing_or_empty");
|
|
501
|
-
if (!Array.isArray(events) || events.length === 0) return insufficient("events_missing", trace.length);
|
|
502
|
-
for (const event of events) {
|
|
503
|
-
const missingPaths = event.predicates.filter((predicate) => !trace.some((sample) => {
|
|
504
|
-
const resolved = resolve(sample, predicate.path);
|
|
505
|
-
return resolved.exists && (!numericOperator(predicate.op) || typeof resolved.value === "number" && Number.isFinite(resolved.value));
|
|
506
|
-
})).map((predicate) => predicate.path);
|
|
507
|
-
if (missingPaths.length) {
|
|
508
|
-
return insufficient("required_trace_field_missing", trace.length, [], event.label, Array.from(new Set(missingPaths)));
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const witnesses = [];
|
|
512
|
-
let cursor = 0;
|
|
513
|
-
for (const event of events) {
|
|
514
|
-
let witnessIndex = -1;
|
|
515
|
-
for (let index = cursor; index < trace.length; index += 1) {
|
|
516
|
-
if (event.predicates.every((predicate) => {
|
|
517
|
-
const resolved = resolve(trace[index], predicate.path);
|
|
518
|
-
return resolved.exists && matches(resolved.value, predicate);
|
|
519
|
-
})) {
|
|
520
|
-
witnessIndex = index;
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (witnessIndex < 0) {
|
|
525
|
-
return {
|
|
526
|
-
version: "riddle-proof.ordered-trace-assessment.v1",
|
|
527
|
-
status: "failed",
|
|
528
|
-
trace_length: trace.length,
|
|
529
|
-
witnesses,
|
|
530
|
-
missing_event: event.label,
|
|
531
|
-
reason: "ordered_event_not_observed"
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
witnesses.push({
|
|
535
|
-
label: event.label,
|
|
536
|
-
index: witnessIndex,
|
|
537
|
-
observations: event.predicates.map((predicate) => {
|
|
538
|
-
const observed = resolve(trace[witnessIndex], predicate.path).value;
|
|
539
|
-
return {
|
|
540
|
-
path: predicate.path,
|
|
541
|
-
op: predicate.op,
|
|
542
|
-
expected: predicate.value,
|
|
543
|
-
observed
|
|
544
|
-
};
|
|
545
|
-
})
|
|
546
|
-
});
|
|
547
|
-
cursor = witnessIndex + 1;
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
version: "riddle-proof.ordered-trace-assessment.v1",
|
|
551
|
-
status: "passed",
|
|
552
|
-
trace_length: trace.length,
|
|
553
|
-
witnesses
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
function assessRiddleProofOrderedTraceSetupResults(results, setupActionLabel, tracePath, events) {
|
|
557
|
-
const insufficient = (reason) => ({
|
|
558
|
-
version: "riddle-proof.ordered-trace-assessment.v1",
|
|
559
|
-
status: "proof_insufficient",
|
|
560
|
-
trace_length: 0,
|
|
561
|
-
witnesses: [],
|
|
562
|
-
reason
|
|
563
|
-
});
|
|
564
|
-
if (!Array.isArray(results)) return insufficient("setup_results_missing");
|
|
565
|
-
const source = results.find((item) => item && typeof item === "object" && !Array.isArray(item) && item.label === setupActionLabel);
|
|
566
|
-
if (!source) return insufficient("setup_action_result_missing");
|
|
567
|
-
if (!Object.hasOwn(source, "returned")) return insufficient("setup_action_return_missing");
|
|
568
|
-
const segments = tracePath.split(".").map((segment) => segment.trim()).filter(Boolean);
|
|
569
|
-
let trace = source.returned;
|
|
570
|
-
for (const segment of segments) {
|
|
571
|
-
if (trace === null || typeof trace !== "object" || Array.isArray(trace) || !Object.hasOwn(trace, segment)) {
|
|
572
|
-
return insufficient("trace_path_missing");
|
|
573
|
-
}
|
|
574
|
-
trace = trace[segment];
|
|
575
|
-
}
|
|
576
|
-
return assessRiddleProofOrderedTrace(trace, events);
|
|
577
|
-
}
|
|
578
199
|
function evaluateHttpStatusBodyJsonAssertion(root, assertion) {
|
|
579
200
|
const resolved = resolveJsonPath(root, assertion.path);
|
|
580
201
|
const errors = [];
|
|
@@ -630,3494 +251,286 @@ function evaluateHttpStatusBodyJsonAssertions(bodyText, assertions) {
|
|
|
630
251
|
}
|
|
631
252
|
return expected.map((assertion) => evaluateHttpStatusBodyJsonAssertion(parsed, assertion));
|
|
632
253
|
}
|
|
633
|
-
function
|
|
634
|
-
|
|
635
|
-
if (!text) return void 0;
|
|
636
|
-
if (text.length <= limit) return text;
|
|
637
|
-
return `${text.slice(0, Math.max(0, limit - 15)).trimEnd()}... (${text.length} chars)`;
|
|
638
|
-
}
|
|
639
|
-
function profileSetupResultAction(value) {
|
|
640
|
-
const action = value.action ?? value.type;
|
|
641
|
-
return typeof action === "string" && action ? action : "unknown";
|
|
254
|
+
function checkLabel(check) {
|
|
255
|
+
return check.label || check.type;
|
|
642
256
|
}
|
|
643
|
-
function
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
257
|
+
function httpStatusRequestUrl(check, baseUrl) {
|
|
258
|
+
const rawUrl = check.url || "";
|
|
259
|
+
if (!rawUrl) return "";
|
|
260
|
+
try {
|
|
261
|
+
if (baseUrl && rawUrl.startsWith("/") && !rawUrl.startsWith("//")) {
|
|
262
|
+
const base = new URL(baseUrl);
|
|
263
|
+
const mountPrefix = previewMountPrefix(base.pathname);
|
|
264
|
+
if (mountPrefix) {
|
|
265
|
+
const requested = new URL(rawUrl, base.origin);
|
|
266
|
+
base.pathname = joinMountedRoutePath(mountPrefix, requested.pathname);
|
|
267
|
+
base.search = requested.search;
|
|
268
|
+
base.hash = requested.hash;
|
|
269
|
+
return base.href;
|
|
270
|
+
}
|
|
652
271
|
}
|
|
272
|
+
return baseUrl ? new URL(rawUrl, baseUrl).href : new URL(rawUrl).href;
|
|
273
|
+
} catch {
|
|
274
|
+
return rawUrl;
|
|
653
275
|
}
|
|
654
|
-
return urls.slice(0, 10);
|
|
655
|
-
}
|
|
656
|
-
function profileSetupActionCounts(results) {
|
|
657
|
-
const counts = {};
|
|
658
|
-
for (const result of results) {
|
|
659
|
-
const action = profileSetupResultAction(result);
|
|
660
|
-
counts[action] = (counts[action] || 0) + 1;
|
|
661
|
-
}
|
|
662
|
-
return toJsonValue(counts);
|
|
663
276
|
}
|
|
664
|
-
function
|
|
665
|
-
return
|
|
277
|
+
function httpStatusMethod(check) {
|
|
278
|
+
return (check.method || "GET").toUpperCase();
|
|
666
279
|
}
|
|
667
|
-
function
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
path: result.path ?? null,
|
|
672
|
-
until_path: result.until_path ?? null,
|
|
673
|
-
until_value: result.until_value ?? null,
|
|
674
|
-
until_expected_value: result.until_expected_value ?? null,
|
|
675
|
-
call_count: result.call_count ?? null,
|
|
676
|
-
max_calls: result.max_calls ?? null,
|
|
677
|
-
reason: result.reason ?? result.error ?? null
|
|
678
|
-
}));
|
|
280
|
+
function httpStatusAllowedStatuses(check) {
|
|
281
|
+
if (check.allowed_statuses?.length) return check.allowed_statuses;
|
|
282
|
+
if (check.expected_status !== void 0) return [check.expected_status];
|
|
283
|
+
return void 0;
|
|
679
284
|
}
|
|
680
|
-
function
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
label: result.label ?? null,
|
|
685
|
-
ok: result.ok !== false,
|
|
686
|
-
path: result.path ?? null,
|
|
687
|
-
return_captured: result.return_captured ?? null,
|
|
688
|
-
return_stored_to: result.return_stored_to ?? null,
|
|
689
|
-
reason: result.reason ?? result.store_reason ?? null
|
|
690
|
-
};
|
|
691
|
-
if (result.error !== void 0) receipt.error = result.error;
|
|
692
|
-
if (result.returned !== void 0) receipt.returned = result.returned;
|
|
693
|
-
if (result.expected_return !== void 0) receipt.expected_return = result.expected_return;
|
|
694
|
-
const returnSummary = profileSetupReturnSummary(result);
|
|
695
|
-
if (returnSummary.length) receipt.return_summary = returnSummary;
|
|
696
|
-
return receipt;
|
|
697
|
-
});
|
|
285
|
+
function httpStatusIsAllowed(status, check) {
|
|
286
|
+
if (status === void 0) return false;
|
|
287
|
+
const allowed = httpStatusAllowedStatuses(check);
|
|
288
|
+
return allowed?.length ? allowed.includes(status) : status >= 200 && status < 400;
|
|
698
289
|
}
|
|
699
|
-
function
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
label: result.label ?? null,
|
|
704
|
-
ok: result.ok !== false,
|
|
705
|
-
script_length: result.script_length ?? null,
|
|
706
|
-
return_captured: result.return_captured ?? null,
|
|
707
|
-
return_stored_to: result.return_stored_to ?? null,
|
|
708
|
-
reason: result.reason ?? result.store_reason ?? null
|
|
709
|
-
};
|
|
710
|
-
if (result.error !== void 0) receipt.error = result.error;
|
|
711
|
-
if (result.returned !== void 0) receipt.returned = result.returned;
|
|
712
|
-
if (result.expected_return !== void 0) receipt.expected_return = result.expected_return;
|
|
713
|
-
const returnSummary = profileSetupReturnSummary(result);
|
|
714
|
-
if (returnSummary.length) receipt.return_summary = returnSummary;
|
|
715
|
-
return receipt;
|
|
716
|
-
});
|
|
290
|
+
function linkStatusObservedBytes(result) {
|
|
291
|
+
const bytes = numberValue(result.bytes);
|
|
292
|
+
const contentLength = numberValue(result.content_length);
|
|
293
|
+
return Math.max(bytes ?? 0, contentLength ?? 0) || void 0;
|
|
717
294
|
}
|
|
718
|
-
function
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
ok: result.ok !== false,
|
|
722
|
-
random_enabled: result.random_enabled ?? null,
|
|
723
|
-
random_queue_added: result.random_queue_added ?? null,
|
|
724
|
-
random_queue_length: result.random_queue_length ?? null,
|
|
725
|
-
random_queue_mode: result.random_queue_mode ?? null,
|
|
726
|
-
random_underflow_count: result.random_underflow_count ?? null,
|
|
727
|
-
clock_enabled: result.clock_enabled ?? null,
|
|
728
|
-
previous_now: result.previous_now ?? null,
|
|
729
|
-
now: result.now ?? null,
|
|
730
|
-
advance_ms: result.advance_ms ?? null,
|
|
731
|
-
restored: result.restored ?? null,
|
|
732
|
-
reason: result.reason ?? result.error ?? null
|
|
733
|
-
}));
|
|
295
|
+
function normalizeLinkStatusContentType(value) {
|
|
296
|
+
const normalized = value?.split(";")[0]?.trim().toLowerCase();
|
|
297
|
+
return normalized || void 0;
|
|
734
298
|
}
|
|
735
|
-
function
|
|
736
|
-
|
|
737
|
-
if (
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const path2 = item.trim();
|
|
742
|
-
if (path2) fields.push({ path: path2 });
|
|
743
|
-
continue;
|
|
744
|
-
}
|
|
745
|
-
if (!isRecord(item)) continue;
|
|
746
|
-
const path = stringValue(item.path) ?? stringValue(item.key) ?? stringValue(item.json_path) ?? stringValue(item.jsonPath);
|
|
747
|
-
if (!path) continue;
|
|
748
|
-
const label = stringValue(item.label) ?? stringValue(item.name) ?? stringValue(item.title);
|
|
749
|
-
fields.push(label ? { path, label } : { path });
|
|
750
|
-
}
|
|
751
|
-
return fields;
|
|
299
|
+
function linkStatusContentTypesMatch(actual, expected) {
|
|
300
|
+
if (!actual || !expected) return false;
|
|
301
|
+
if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
|
|
302
|
+
if (actual === expected) return true;
|
|
303
|
+
const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
|
|
304
|
+
return yamlTypes.has(actual) && yamlTypes.has(expected);
|
|
752
305
|
}
|
|
753
|
-
function
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
if (resolved.exists) receipt.value = toJsonValue(resolved.value);
|
|
763
|
-
if (resolved.error) receipt.reason = resolved.error;
|
|
764
|
-
return receipt;
|
|
306
|
+
function linkStatusContentTypeOk(result, check) {
|
|
307
|
+
const expected = check.allowed_content_types;
|
|
308
|
+
if (!expected?.length) return true;
|
|
309
|
+
const actual = normalizeLinkStatusContentType(stringValue(result.content_type));
|
|
310
|
+
if (!actual) return false;
|
|
311
|
+
return expected.some((contentType) => {
|
|
312
|
+
const normalized = normalizeLinkStatusContentType(contentType);
|
|
313
|
+
if (!normalized) return false;
|
|
314
|
+
return linkStatusContentTypesMatch(actual, normalized);
|
|
765
315
|
});
|
|
766
316
|
}
|
|
767
|
-
function
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
frame_selector: result.frame_selector ?? null,
|
|
773
|
-
requested_value: result.requested_value ?? null,
|
|
774
|
-
actual_value: result.actual_value ?? null,
|
|
775
|
-
before_value: result.before_value ?? null,
|
|
776
|
-
value_as_number: result.value_as_number ?? null,
|
|
777
|
-
min: result.min ?? null,
|
|
778
|
-
max: result.max ?? null,
|
|
779
|
-
step: result.step ?? null,
|
|
780
|
-
reason: result.reason ?? result.error ?? null
|
|
781
|
-
}));
|
|
782
|
-
}
|
|
783
|
-
function profileSetupDragReceipts(results) {
|
|
784
|
-
return results.filter((result) => profileSetupResultAction(result) === "drag").map((result) => ({
|
|
785
|
-
ordinal: result.ordinal ?? null,
|
|
786
|
-
ok: result.ok !== false,
|
|
787
|
-
selector: result.selector ?? null,
|
|
788
|
-
frame_selector: result.frame_selector ?? null,
|
|
789
|
-
pointer_type: result.pointer_type ?? null,
|
|
790
|
-
input_dispatch: result.input_dispatch ?? null,
|
|
791
|
-
coordinate_mode: result.coordinate_mode ?? null,
|
|
792
|
-
from_x: result.from_x ?? null,
|
|
793
|
-
from_y: result.from_y ?? null,
|
|
794
|
-
to_x: result.to_x ?? null,
|
|
795
|
-
to_y: result.to_y ?? null,
|
|
796
|
-
steps: result.steps ?? null,
|
|
797
|
-
duration_ms: result.duration_ms ?? null,
|
|
798
|
-
reason: result.reason ?? result.error ?? null
|
|
799
|
-
}));
|
|
317
|
+
function httpStatusBodyContainsFailures(result, check) {
|
|
318
|
+
const expected = check.body_contains?.filter(Boolean) ?? [];
|
|
319
|
+
if (!expected.length) return [];
|
|
320
|
+
const observed = isRecord(result.body_contains) ? result.body_contains : {};
|
|
321
|
+
return expected.filter((text) => observed[text] !== true);
|
|
800
322
|
}
|
|
801
|
-
function
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
frame_selector: result.frame_selector ?? null,
|
|
807
|
-
pointer_type: result.pointer_type ?? null,
|
|
808
|
-
input_dispatch: result.input_dispatch ?? null,
|
|
809
|
-
coordinate_mode: result.coordinate_mode ?? null,
|
|
810
|
-
x: result.x ?? null,
|
|
811
|
-
y: result.y ?? null,
|
|
812
|
-
duration_ms: result.duration_ms ?? null,
|
|
813
|
-
reason: result.reason ?? result.error ?? null
|
|
814
|
-
}));
|
|
815
|
-
}
|
|
816
|
-
function profileSetupTapUntilReceipts(results) {
|
|
817
|
-
return results.filter((result) => profileSetupResultAction(result) === "tap_until").map((result) => ({
|
|
818
|
-
ordinal: result.ordinal ?? null,
|
|
819
|
-
ok: result.ok !== false,
|
|
820
|
-
selector: result.selector ?? null,
|
|
821
|
-
frame_selector: result.frame_selector ?? null,
|
|
822
|
-
pointer_type: result.pointer_type ?? null,
|
|
823
|
-
input_dispatch: result.input_dispatch ?? null,
|
|
824
|
-
coordinate_mode: result.coordinate_mode ?? null,
|
|
825
|
-
x: result.x ?? null,
|
|
826
|
-
y: result.y ?? null,
|
|
827
|
-
duration_ms: result.duration_ms ?? null,
|
|
828
|
-
until_path: result.until_path ?? null,
|
|
829
|
-
until_value: result.until_value ?? null,
|
|
830
|
-
until_expected_value: result.until_expected_value ?? null,
|
|
831
|
-
tap_count: result.tap_count ?? null,
|
|
832
|
-
max_taps: result.max_taps ?? result.max_calls ?? null,
|
|
833
|
-
tap_burst_size: result.tap_burst_size ?? null,
|
|
834
|
-
condition_check_count: result.condition_check_count ?? null,
|
|
835
|
-
settle_ms: result.settle_ms ?? null,
|
|
836
|
-
elapsed_ms: result.elapsed_ms ?? null,
|
|
837
|
-
interval_ms: result.interval_ms ?? null,
|
|
838
|
-
timeout_ms: result.timeout_ms ?? null,
|
|
839
|
-
reason: result.reason ?? result.error ?? null
|
|
840
|
-
}));
|
|
841
|
-
}
|
|
842
|
-
function profileSetupKeyboardReceipts(results) {
|
|
843
|
-
return results.filter((result) => ["press", "key_down", "key_up"].includes(profileSetupResultAction(result))).map((result) => ({
|
|
844
|
-
action: profileSetupResultAction(result),
|
|
845
|
-
ordinal: result.ordinal ?? null,
|
|
846
|
-
ok: result.ok !== false,
|
|
847
|
-
selector: result.selector ?? null,
|
|
848
|
-
frame_selector: result.frame_selector ?? null,
|
|
849
|
-
key: result.key ?? null,
|
|
850
|
-
hold_ms: result.hold_ms ?? null,
|
|
851
|
-
reason: result.reason ?? result.error ?? null
|
|
852
|
-
}));
|
|
853
|
-
}
|
|
854
|
-
function profileSetupCanvasSignatureReceipts(results) {
|
|
855
|
-
return results.filter((result) => profileSetupResultAction(result) === "canvas_signature").map((result) => ({
|
|
856
|
-
ordinal: result.ordinal ?? null,
|
|
857
|
-
ok: result.ok !== false,
|
|
858
|
-
selector: result.selector ?? null,
|
|
859
|
-
frame_selector: result.frame_selector ?? null,
|
|
860
|
-
label: result.label ?? null,
|
|
861
|
-
hash: result.hash ?? null,
|
|
862
|
-
data_length: result.data_length ?? null,
|
|
863
|
-
width: result.width ?? null,
|
|
864
|
-
height: result.height ?? null,
|
|
865
|
-
css_width: result.css_width ?? null,
|
|
866
|
-
css_height: result.css_height ?? null,
|
|
867
|
-
compare_to: result.compare_to ?? null,
|
|
868
|
-
previous_hash: result.previous_hash ?? null,
|
|
869
|
-
changed: result.changed ?? null,
|
|
870
|
-
return_stored_to: result.return_stored_to ?? null,
|
|
871
|
-
reason: result.reason ?? result.error ?? null
|
|
872
|
-
}));
|
|
873
|
-
}
|
|
874
|
-
function profileSetupCanvasSignatureStableHashGroups(results) {
|
|
875
|
-
const groups = /* @__PURE__ */ new Map();
|
|
876
|
-
for (const receipt of profileSetupCanvasSignatureReceipts(results)) {
|
|
877
|
-
if (receipt.ok === false) continue;
|
|
878
|
-
const hash = stringValue(receipt.hash);
|
|
879
|
-
if (!hash) continue;
|
|
880
|
-
const selector = stringValue(receipt.selector) || "canvas";
|
|
881
|
-
const frameSelector = stringValue(receipt.frame_selector);
|
|
882
|
-
const key = String(frameSelector || "") + "\n" + selector;
|
|
883
|
-
const group = groups.get(key) || { selector, frame_selector: frameSelector, receipts: [] };
|
|
884
|
-
const ordinal = numberValue(receipt.ordinal);
|
|
885
|
-
const label = stringValue(receipt.label) || (ordinal === void 0 ? `capture-${group.receipts.length + 1}` : `#${ordinal}`);
|
|
886
|
-
group.receipts.push({ hash, label, ordinal });
|
|
887
|
-
groups.set(key, group);
|
|
888
|
-
}
|
|
889
|
-
const warnings = [];
|
|
890
|
-
for (const group of groups.values()) {
|
|
891
|
-
const receiptsByHash = /* @__PURE__ */ new Map();
|
|
892
|
-
for (const receipt of group.receipts) {
|
|
893
|
-
const hashReceipts = receiptsByHash.get(receipt.hash) || [];
|
|
894
|
-
hashReceipts.push(receipt);
|
|
895
|
-
receiptsByHash.set(receipt.hash, hashReceipts);
|
|
896
|
-
}
|
|
897
|
-
for (const [hash, receipts] of receiptsByHash.entries()) {
|
|
898
|
-
const labels = [...new Set(receipts.map((receipt) => receipt.label))];
|
|
899
|
-
if (receipts.length < 2 || labels.length < 2) continue;
|
|
900
|
-
const visibleLabels = labels.slice(0, 8);
|
|
901
|
-
warnings.push({
|
|
902
|
-
selector: group.selector,
|
|
903
|
-
frame_selector: group.frame_selector ?? null,
|
|
904
|
-
hash,
|
|
905
|
-
count: receipts.length,
|
|
906
|
-
label_count: labels.length,
|
|
907
|
-
labels: visibleLabels,
|
|
908
|
-
omitted_label_count: Math.max(0, labels.length - visibleLabels.length),
|
|
909
|
-
ordinals: receipts.map((receipt) => receipt.ordinal).filter((value) => value !== void 0).slice(0, 12),
|
|
910
|
-
reason: "stable_canvas_signature_hash"
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
return warnings;
|
|
915
|
-
}
|
|
916
|
-
function profileSetupClickSequenceReceipts(clickedItems) {
|
|
917
|
-
const nthChildPattern = /:nth-child\((\d+)\)/;
|
|
918
|
-
const nthChildTemplatePattern = /:nth-child\(\d+\)/g;
|
|
919
|
-
const groups = /* @__PURE__ */ new Map();
|
|
920
|
-
for (const item of clickedItems) {
|
|
921
|
-
const selector = stringValue(item.selector);
|
|
922
|
-
if (!selector) continue;
|
|
923
|
-
const frameSelector = stringValue(item.frame_selector);
|
|
924
|
-
const clickCountValue = numberValue(item.click_count);
|
|
925
|
-
const clickCount = clickCountValue === void 0 ? 1 : Math.max(1, Math.min(100, Math.floor(clickCountValue)));
|
|
926
|
-
const ordinal = numberValue(item.ordinal);
|
|
927
|
-
const match = nthChildPattern.exec(selector);
|
|
928
|
-
const selectorTemplate = match ? selector.replace(nthChildTemplatePattern, ":nth-child(*)") : selector;
|
|
929
|
-
const valueSource = match ? "nth-child" : "same-selector";
|
|
930
|
-
const key = `${valueSource}
|
|
931
|
-
${frameSelector || ""}
|
|
932
|
-
${selectorTemplate}`;
|
|
933
|
-
const group = groups.get(key) || {
|
|
934
|
-
selector_template: selectorTemplate,
|
|
935
|
-
frame_selector: frameSelector,
|
|
936
|
-
value_source: valueSource,
|
|
937
|
-
sequence: [],
|
|
938
|
-
ordinals: [],
|
|
939
|
-
result_count: 0,
|
|
940
|
-
click_total: 0
|
|
941
|
-
};
|
|
942
|
-
if (match) {
|
|
943
|
-
const value = Number(match[1]);
|
|
944
|
-
for (let index = 0; index < clickCount; index += 1) group.sequence.push(value);
|
|
945
|
-
}
|
|
946
|
-
if (ordinal !== void 0) group.ordinals.push(ordinal);
|
|
947
|
-
group.result_count += 1;
|
|
948
|
-
group.click_total += clickCount;
|
|
949
|
-
groups.set(key, group);
|
|
950
|
-
}
|
|
951
|
-
return [...groups.values()].filter((group) => group.result_count >= 4).map((group) => {
|
|
952
|
-
const sequence = group.sequence.slice(0, 32);
|
|
953
|
-
const ordinals = group.ordinals.slice(0, 16);
|
|
954
|
-
return {
|
|
955
|
-
selector_template: group.selector_template,
|
|
956
|
-
frame_selector: group.frame_selector ?? null,
|
|
957
|
-
value_source: group.value_source,
|
|
958
|
-
result_count: group.result_count,
|
|
959
|
-
click_total: group.click_total,
|
|
960
|
-
sequence,
|
|
961
|
-
omitted_sequence_count: Math.max(0, group.sequence.length - sequence.length),
|
|
962
|
-
ordinals,
|
|
963
|
-
omitted_ordinal_count: Math.max(0, group.ordinals.length - ordinals.length)
|
|
964
|
-
};
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
function sampleProfileSetupSummaryItems(items, limit) {
|
|
968
|
-
if (items.length <= limit) return items;
|
|
969
|
-
const firstCount = Math.floor(limit / 2);
|
|
970
|
-
const lastCount = limit - firstCount;
|
|
971
|
-
return [...items.slice(0, firstCount), ...items.slice(-lastCount)];
|
|
972
|
-
}
|
|
973
|
-
function profileScreenshotLabels(viewports) {
|
|
974
|
-
const labels = [];
|
|
975
|
-
for (const viewport of viewports || []) {
|
|
976
|
-
if (viewport.screenshot_label) labels.push(viewport.screenshot_label);
|
|
977
|
-
labels.push(...profileSetupScreenshotLabels(viewport.setup_action_results || []));
|
|
978
|
-
}
|
|
979
|
-
return labels;
|
|
980
|
-
}
|
|
981
|
-
function profileFinalScreenshotLabels(viewports) {
|
|
982
|
-
return (viewports || []).map((viewport) => viewport.screenshot_label).filter((label) => typeof label === "string" && Boolean(label.trim()));
|
|
983
|
-
}
|
|
984
|
-
function profileAllSetupScreenshotLabels(viewports) {
|
|
985
|
-
return (viewports || []).flatMap((viewport) => profileSetupScreenshotLabels(viewport.setup_action_results || []));
|
|
986
|
-
}
|
|
987
|
-
function profileSetupSummary(viewports, actionCount, expectedActionCountByViewport, finalScreenshotFullPage) {
|
|
988
|
-
const normalizedFinalScreenshotFullPage = finalScreenshotFullPage === void 0 ? void 0 : finalScreenshotFullPage !== false;
|
|
989
|
-
const finalScreenshotCount = viewports.filter((viewport) => typeof viewport.screenshot_label === "string" && viewport.screenshot_label.trim()).length;
|
|
990
|
-
return toJsonValue({
|
|
991
|
-
viewport_count: viewports.length,
|
|
992
|
-
action_count: actionCount ?? null,
|
|
993
|
-
final_screenshot_count: finalScreenshotCount,
|
|
994
|
-
final_screenshot_full_page: normalizedFinalScreenshotFullPage ?? null,
|
|
995
|
-
final_screenshot_mode: normalizedFinalScreenshotFullPage === void 0 ? null : normalizedFinalScreenshotFullPage ? "full_page" : "viewport",
|
|
996
|
-
viewports: viewports.map((viewport) => {
|
|
997
|
-
const expectedActionCount = expectedActionCountByViewport?.get(viewport.name) ?? actionCount;
|
|
998
|
-
const viewportFinalScreenshotFullPage = typeof viewport.screenshot_full_page === "boolean" ? viewport.screenshot_full_page : normalizedFinalScreenshotFullPage;
|
|
999
|
-
const results = viewport.setup_action_results || [];
|
|
1000
|
-
const failed = results.filter((result) => result.ok === false && result.optional !== true);
|
|
1001
|
-
const optionalFailed = results.filter((result) => result.ok === false && result.optional === true);
|
|
1002
|
-
const successfulClicks = results.filter((result) => profileSetupResultAction(result) === "click" && result.ok !== false);
|
|
1003
|
-
const clickCountValues = successfulClicks.map((result) => typeof result.click_count === "number" && Number.isFinite(result.click_count) && result.click_count > 1 ? result.click_count : void 0).filter((value) => value !== void 0);
|
|
1004
|
-
const windowCallUntilReceipts = profileSetupWindowCallUntilReceipts(results);
|
|
1005
|
-
const windowCallUntilCallCounts = windowCallUntilReceipts.map((result) => typeof result.call_count === "number" && Number.isFinite(result.call_count) ? result.call_count : void 0).filter((value) => value !== void 0);
|
|
1006
|
-
const sampledWindowCallUntilReceipts = sampleProfileSetupSummaryItems(windowCallUntilReceipts, 8);
|
|
1007
|
-
const windowCallReceipts = profileSetupWindowCallReceipts(results);
|
|
1008
|
-
const windowCallStoredTotal = windowCallReceipts.filter((result) => typeof result.return_stored_to === "string" && result.return_stored_to.trim()).length;
|
|
1009
|
-
const windowCallCapturedTotal = windowCallReceipts.filter((result) => result.return_captured === true).length;
|
|
1010
|
-
const sampledWindowCallReceipts = sampleProfileSetupSummaryItems(windowCallReceipts, 8);
|
|
1011
|
-
const windowEvalReceipts = profileSetupWindowEvalReceipts(results);
|
|
1012
|
-
const windowEvalStoredTotal = windowEvalReceipts.filter((result) => typeof result.return_stored_to === "string" && result.return_stored_to.trim()).length;
|
|
1013
|
-
const windowEvalCapturedTotal = windowEvalReceipts.filter((result) => result.return_captured === true).length;
|
|
1014
|
-
const sampledWindowEvalReceipts = sampleProfileSetupSummaryItems(windowEvalReceipts, 8);
|
|
1015
|
-
const deterministicRuntimeReceipts = profileSetupDeterministicRuntimeReceipts(results);
|
|
1016
|
-
const sampledDeterministicRuntimeReceipts = sampleProfileSetupSummaryItems(deterministicRuntimeReceipts, 8);
|
|
1017
|
-
const rangeValueReceipts = profileSetupRangeValueReceipts(results);
|
|
1018
|
-
const sampledRangeValueReceipts = sampleProfileSetupSummaryItems(rangeValueReceipts, 8);
|
|
1019
|
-
const dragReceipts = profileSetupDragReceipts(results);
|
|
1020
|
-
const sampledDragReceipts = sampleProfileSetupSummaryItems(dragReceipts, 8);
|
|
1021
|
-
const tapReceipts = profileSetupTapReceipts(results);
|
|
1022
|
-
const sampledTapReceipts = sampleProfileSetupSummaryItems(tapReceipts, 8);
|
|
1023
|
-
const tapUntilReceipts = profileSetupTapUntilReceipts(results);
|
|
1024
|
-
const tapUntilTapCounts = tapUntilReceipts.map((result) => typeof result.tap_count === "number" && Number.isFinite(result.tap_count) ? result.tap_count : void 0).filter((value) => value !== void 0);
|
|
1025
|
-
const sampledTapUntilReceipts = sampleProfileSetupSummaryItems(tapUntilReceipts, 8);
|
|
1026
|
-
const keyboardReceipts = profileSetupKeyboardReceipts(results);
|
|
1027
|
-
const sampledKeyboardReceipts = sampleProfileSetupSummaryItems(keyboardReceipts, 8);
|
|
1028
|
-
const canvasSignatureReceipts = profileSetupCanvasSignatureReceipts(results);
|
|
1029
|
-
const sampledCanvasSignatureReceipts = sampleProfileSetupSummaryItems(canvasSignatureReceipts, 8);
|
|
1030
|
-
const clickedItems = results.filter((result) => profileSetupResultAction(result) === "click" && result.ok !== false).map((result) => {
|
|
1031
|
-
const clickCount = typeof result.click_count === "number" && Number.isFinite(result.click_count) && result.click_count > 1 ? result.click_count : void 0;
|
|
1032
|
-
return {
|
|
1033
|
-
ordinal: result.ordinal ?? null,
|
|
1034
|
-
selector: result.selector ?? null,
|
|
1035
|
-
frame_selector: result.frame_selector ?? null,
|
|
1036
|
-
text: compactProfileSetupSummaryText(result.text),
|
|
1037
|
-
...result.fallback_to_tap === true ? { fallback_to_tap: true } : {},
|
|
1038
|
-
...result.input_dispatch ? { input_dispatch: result.input_dispatch } : {},
|
|
1039
|
-
...result.click_error ? { click_error: compactProfileSetupSummaryText(result.click_error) } : {},
|
|
1040
|
-
...clickCount ? { click_count: clickCount } : {}
|
|
1041
|
-
};
|
|
1042
|
-
});
|
|
1043
|
-
const clicked = sampleProfileSetupSummaryItems(clickedItems, 8);
|
|
1044
|
-
const clickSequences = profileSetupClickSequenceReceipts(clickedItems);
|
|
1045
|
-
const sampledClickSequences = sampleProfileSetupSummaryItems(clickSequences, 6);
|
|
1046
|
-
const text_samples = results.filter((result) => result.ok !== false && typeof result.text === "string" && (profileSetupResultAction(result) === "assert_text_visible" || profileSetupResultAction(result) === "assert_text_absent" || profileSetupResultAction(result) === "wait_for_text")).map((result) => ({
|
|
1047
|
-
ordinal: result.ordinal ?? null,
|
|
1048
|
-
action: profileSetupResultAction(result),
|
|
1049
|
-
frame_selector: result.frame_selector ?? null,
|
|
1050
|
-
text: compactProfileSetupSummaryText(result.text)
|
|
1051
|
-
})).filter((item) => item.text).slice(-6);
|
|
1052
|
-
return {
|
|
1053
|
-
name: viewport.name,
|
|
1054
|
-
expected_action_count: expectedActionCount ?? null,
|
|
1055
|
-
ok: (expectedActionCount === void 0 ? results.length > 0 : results.length >= expectedActionCount) && failed.length === 0,
|
|
1056
|
-
result_count: results.length,
|
|
1057
|
-
observed_path: viewport.route?.observed ?? null,
|
|
1058
|
-
final_url: viewport.url ?? null,
|
|
1059
|
-
action_counts: profileSetupActionCounts(results),
|
|
1060
|
-
frame_action_count: results.filter((result) => result.frame_selector).length,
|
|
1061
|
-
frame_urls: profileSetupFrameUrls(viewport),
|
|
1062
|
-
final_screenshot: viewport.screenshot_label ?? null,
|
|
1063
|
-
final_screenshot_full_page: viewportFinalScreenshotFullPage ?? null,
|
|
1064
|
-
setup_screenshots: profileSetupScreenshotLabels(results),
|
|
1065
|
-
clicked_total: clickedItems.length,
|
|
1066
|
-
clicked_truncated: clickedItems.length > clicked.length,
|
|
1067
|
-
click_sequence_total: clickSequences.length,
|
|
1068
|
-
click_sequence_truncated: clickSequences.length > sampledClickSequences.length,
|
|
1069
|
-
click_sequences: sampledClickSequences,
|
|
1070
|
-
click_count_action_total: clickCountValues.length,
|
|
1071
|
-
click_count_value_total: clickCountValues.reduce((sum, value) => sum + value, 0),
|
|
1072
|
-
window_call_until_total: windowCallUntilReceipts.length,
|
|
1073
|
-
window_call_until_call_total: windowCallUntilCallCounts.reduce((sum, value) => sum + value, 0),
|
|
1074
|
-
window_call_until_truncated: windowCallUntilReceipts.length > sampledWindowCallUntilReceipts.length,
|
|
1075
|
-
window_call_until: sampledWindowCallUntilReceipts,
|
|
1076
|
-
window_call_total: windowCallReceipts.length,
|
|
1077
|
-
window_call_stored_total: windowCallStoredTotal,
|
|
1078
|
-
window_call_captured_total: windowCallCapturedTotal,
|
|
1079
|
-
window_call_truncated: windowCallReceipts.length > sampledWindowCallReceipts.length,
|
|
1080
|
-
window_call: sampledWindowCallReceipts,
|
|
1081
|
-
window_eval_total: windowEvalReceipts.length,
|
|
1082
|
-
window_eval_stored_total: windowEvalStoredTotal,
|
|
1083
|
-
window_eval_captured_total: windowEvalCapturedTotal,
|
|
1084
|
-
window_eval_truncated: windowEvalReceipts.length > sampledWindowEvalReceipts.length,
|
|
1085
|
-
window_eval: sampledWindowEvalReceipts,
|
|
1086
|
-
deterministic_runtime_total: deterministicRuntimeReceipts.length,
|
|
1087
|
-
deterministic_runtime_truncated: deterministicRuntimeReceipts.length > sampledDeterministicRuntimeReceipts.length,
|
|
1088
|
-
deterministic_runtime: sampledDeterministicRuntimeReceipts,
|
|
1089
|
-
set_range_value_total: rangeValueReceipts.length,
|
|
1090
|
-
set_range_value_truncated: rangeValueReceipts.length > sampledRangeValueReceipts.length,
|
|
1091
|
-
set_range_value: sampledRangeValueReceipts,
|
|
1092
|
-
drag_total: dragReceipts.length,
|
|
1093
|
-
drag_truncated: dragReceipts.length > sampledDragReceipts.length,
|
|
1094
|
-
drag: sampledDragReceipts,
|
|
1095
|
-
tap_total: tapReceipts.length,
|
|
1096
|
-
tap_truncated: tapReceipts.length > sampledTapReceipts.length,
|
|
1097
|
-
tap: sampledTapReceipts,
|
|
1098
|
-
tap_until_total: tapUntilReceipts.length,
|
|
1099
|
-
tap_until_tap_total: tapUntilTapCounts.reduce((sum, value) => sum + value, 0),
|
|
1100
|
-
tap_until_truncated: tapUntilReceipts.length > sampledTapUntilReceipts.length,
|
|
1101
|
-
tap_until: sampledTapUntilReceipts,
|
|
1102
|
-
keyboard_total: keyboardReceipts.length,
|
|
1103
|
-
keyboard_truncated: keyboardReceipts.length > sampledKeyboardReceipts.length,
|
|
1104
|
-
keyboard: sampledKeyboardReceipts,
|
|
1105
|
-
canvas_signature_total: canvasSignatureReceipts.length,
|
|
1106
|
-
canvas_signature_truncated: canvasSignatureReceipts.length > sampledCanvasSignatureReceipts.length,
|
|
1107
|
-
canvas_signature: sampledCanvasSignatureReceipts,
|
|
1108
|
-
canvas_signature_stable_hash_groups: profileSetupCanvasSignatureStableHashGroups(results),
|
|
1109
|
-
clicked,
|
|
1110
|
-
text_samples,
|
|
1111
|
-
failed: failed.map((result) => ({
|
|
1112
|
-
ordinal: result.ordinal ?? null,
|
|
1113
|
-
action: profileSetupResultAction(result),
|
|
1114
|
-
selector: result.selector ?? null,
|
|
1115
|
-
frame_selector: result.frame_selector ?? null,
|
|
1116
|
-
reason: result.reason ?? result.error ?? null,
|
|
1117
|
-
error: result.error ?? null,
|
|
1118
|
-
case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text)
|
|
1119
|
-
})),
|
|
1120
|
-
optional_failed: optionalFailed.map((result) => ({
|
|
1121
|
-
ordinal: result.ordinal ?? null,
|
|
1122
|
-
action: profileSetupResultAction(result),
|
|
1123
|
-
selector: result.selector ?? null,
|
|
1124
|
-
frame_selector: result.frame_selector ?? null,
|
|
1125
|
-
reason: result.reason ?? result.error ?? null,
|
|
1126
|
-
error: result.error ?? null,
|
|
1127
|
-
case_insensitive_text: compactProfileSetupSummaryText(result.case_insensitive_text)
|
|
1128
|
-
}))
|
|
1129
|
-
};
|
|
1130
|
-
})
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
function normalizeName(value, fallback) {
|
|
1134
|
-
const name = stringValue(value) || fallback;
|
|
1135
|
-
return name.replace(/\s+/g, " ").trim();
|
|
1136
|
-
}
|
|
1137
|
-
function slugifyRiddleProofProfileName(value) {
|
|
1138
|
-
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "profile";
|
|
1139
|
-
}
|
|
1140
|
-
function normalizeViewport(input, index) {
|
|
1141
|
-
if (!isRecord(input)) throw new Error(`target.viewports[${index}] must be an object.`);
|
|
1142
|
-
const width = numberValue(input.width);
|
|
1143
|
-
const height = numberValue(input.height);
|
|
1144
|
-
if (!width || !height || width < 100 || height < 100) {
|
|
1145
|
-
throw new Error(`target.viewports[${index}] requires numeric width and height >= 100.`);
|
|
1146
|
-
}
|
|
1147
|
-
const hasTouch = booleanValue(valueFromOwn(input, "hasTouch", "has_touch"));
|
|
1148
|
-
const isMobile = booleanValue(valueFromOwn(input, "isMobile", "is_mobile"));
|
|
1149
|
-
return {
|
|
1150
|
-
name: normalizeName(input.name || input.label, `viewport-${index + 1}`),
|
|
1151
|
-
width: Math.round(width),
|
|
1152
|
-
height: Math.round(height),
|
|
1153
|
-
...hasTouch === void 0 ? {} : { hasTouch },
|
|
1154
|
-
...isMobile === void 0 ? {} : { isMobile }
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
function normalizeViewports(value) {
|
|
1158
|
-
if (value === void 0) return [...DEFAULT_VIEWPORTS];
|
|
1159
|
-
if (!Array.isArray(value) || value.length === 0) throw new Error("target.viewports must be a non-empty array.");
|
|
1160
|
-
return value.map(normalizeViewport);
|
|
1161
|
-
}
|
|
1162
|
-
function isSupportedCheckType(value) {
|
|
1163
|
-
return RIDDLE_PROOF_PROFILE_CHECK_TYPES.includes(value);
|
|
1164
|
-
}
|
|
1165
|
-
function normalizeSetupActionType(value, index) {
|
|
1166
|
-
const normalizedInput = String(value || "").trim().replace(/-/g, "_");
|
|
1167
|
-
const normalized = normalizedInput === "clear_browser_storage" ? "clear_storage" : normalizedInput === "reset_console" || normalizedInput === "clear_browser_console" || normalizedInput === "reset_browser_console" ? "clear_console" : normalizedInput === "pointer_drag" || normalizedInput === "mouse_drag" || normalizedInput === "drag_to" ? "drag" : normalizedInput === "pointer_tap" || normalizedInput === "touch_tap" || normalizedInput === "canvas_tap" ? "tap" : normalizedInput === "tap_until" || normalizedInput === "pointer_tap_until" || normalizedInput === "touch_tap_until" || normalizedInput === "canvas_tap_until" || normalizedInput === "tap_repeat_until" || normalizedInput === "repeat_tap_until" ? "tap_until" : normalizedInput === "keyboard_press" || normalizedInput === "key_press" ? "press" : normalizedInput === "keyboard_down" || normalizedInput === "key_down" || normalizedInput === "keydown" || normalizedInput === "press_down" ? "key_down" : normalizedInput === "keyboard_up" || normalizedInput === "key_up" || normalizedInput === "keyup" || normalizedInput === "press_up" || normalizedInput === "release_key" || normalizedInput === "key_release" ? "key_up" : normalizedInput === "set_slider_value" || normalizedInput === "slider_value" || normalizedInput === "set_slider" || normalizedInput === "set_range" || normalizedInput === "range_value" || normalizedInput === "range_input" || normalizedInput === "set_range_input" ? "set_range_value" : normalizedInput === "deterministic_runtime" || normalizedInput === "mock_runtime" || normalizedInput === "mock_random" || normalizedInput === "mock_random_queue" || normalizedInput === "seed_random_queue" || normalizedInput === "set_random_queue" || normalizedInput === "mock_clock" || normalizedInput === "set_mock_clock" || normalizedInput === "set_runtime_determinism" || normalizedInput === "runtime_determinism" ? "deterministic_runtime" : normalizedInput === "canvas_hash" || normalizedInput === "capture_canvas_hash" || normalizedInput === "capture_canvas_signature" || normalizedInput === "canvas_state_signature" ? "canvas_signature" : normalizedInput === "capture_screenshot" || normalizedInput === "save_screenshot" || normalizedInput === "setup_screenshot" ? "screenshot" : normalizedInput === "accept_dialog" || normalizedInput === "accept_dialogs" || normalizedInput === "confirm_dialog" || normalizedInput === "set_dialog_response" ? "dialog_response" : normalizedInput === "dismiss_dialog" || normalizedInput === "dismiss_dialogs" || normalizedInput === "cancel_dialog" ? "dialog_response" : normalizedInput === "window_call_until" || normalizedInput === "call_until" || normalizedInput === "window_call_repeat_until" || normalizedInput === "repeat_window_call_until" ? "window_call_until" : normalizedInput === "window_evaluate" || normalizedInput === "browser_eval" || normalizedInput === "browser_evaluate" || normalizedInput === "evaluate_script" || normalizedInput === "profile_script" ? "window_eval" : normalizedInput;
|
|
1168
|
-
if (RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES.includes(normalized)) {
|
|
1169
|
-
return normalized;
|
|
1170
|
-
}
|
|
1171
|
-
throw new Error(`target.setup_actions[${index}].type ${value || "(missing)"} is not supported. Supported actions: ${RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES.join(", ")}`);
|
|
1172
|
-
}
|
|
1173
|
-
function normalizeSetupActionStorage(value, index) {
|
|
1174
|
-
if (value === void 0 || value === null || value === "") return void 0;
|
|
1175
|
-
const normalized = String(value).trim().replace(/-/g, "_");
|
|
1176
|
-
if (normalized === "local" || normalized === "local_storage") return "local";
|
|
1177
|
-
if (normalized === "session" || normalized === "session_storage") return "session";
|
|
1178
|
-
if (normalized === "both" || normalized === "all") return "both";
|
|
1179
|
-
throw new Error(`target.setup_actions[${index}].storage ${String(value)} is not supported. Supported storage values: local, session, both.`);
|
|
1180
|
-
}
|
|
1181
|
-
function normalizeSetupActionArgs(input, index) {
|
|
1182
|
-
const argsInput = valueFromOwn(input, "args", "arguments", "args_json", "argsJson");
|
|
1183
|
-
if (argsInput === void 0) return void 0;
|
|
1184
|
-
if (!Array.isArray(argsInput)) {
|
|
1185
|
-
throw new Error(`target.setup_actions[${index}] window_call/window_eval args must be an array.`);
|
|
1186
|
-
}
|
|
1187
|
-
return argsInput.map(toJsonValue);
|
|
1188
|
-
}
|
|
1189
|
-
function normalizeReturnSummaryFields(input, index) {
|
|
1190
|
-
const fieldsInput = valueFromOwn(
|
|
1191
|
-
input,
|
|
1192
|
-
"return_summary_fields",
|
|
1193
|
-
"returnSummaryFields",
|
|
1194
|
-
"summary_fields",
|
|
1195
|
-
"summaryFields",
|
|
1196
|
-
"receipt_fields",
|
|
1197
|
-
"receiptFields",
|
|
1198
|
-
"return_receipt_fields",
|
|
1199
|
-
"returnReceiptFields"
|
|
1200
|
-
);
|
|
1201
|
-
if (fieldsInput === void 0) return void 0;
|
|
1202
|
-
if (!Array.isArray(fieldsInput)) {
|
|
1203
|
-
throw new Error(`target.setup_actions[${index}].return_summary_fields must be an array.`);
|
|
1204
|
-
}
|
|
1205
|
-
return fieldsInput.map((field, fieldIndex) => {
|
|
1206
|
-
if (typeof field === "string") {
|
|
1207
|
-
const path2 = field.trim();
|
|
1208
|
-
if (!path2) throw new Error(`target.setup_actions[${index}].return_summary_fields[${fieldIndex}] requires path.`);
|
|
1209
|
-
return { path: path2 };
|
|
1210
|
-
}
|
|
1211
|
-
if (!isRecord(field)) {
|
|
1212
|
-
throw new Error(`target.setup_actions[${index}].return_summary_fields[${fieldIndex}] must be a string path or object.`);
|
|
1213
|
-
}
|
|
1214
|
-
const path = stringFromOwn(field, "path", "key", "json_path", "jsonPath");
|
|
1215
|
-
if (!path) throw new Error(`target.setup_actions[${index}].return_summary_fields[${fieldIndex}] requires path.`);
|
|
1216
|
-
const label = stringFromOwn(field, "label", "name", "title");
|
|
1217
|
-
return label ? { path, label } : { path };
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
function normalizeSetupActionRepeat(input, index) {
|
|
1221
|
-
const repeat = numberValue(valueFromOwn(input, "repeat", "repeat_count", "repeatCount", "times"));
|
|
1222
|
-
if (repeat === void 0) return void 0;
|
|
1223
|
-
if (!Number.isInteger(repeat) || repeat < 1 || repeat > 100) {
|
|
1224
|
-
throw new Error(`target.setup_actions[${index}].repeat must be an integer from 1 to 100.`);
|
|
1225
|
-
}
|
|
1226
|
-
return repeat;
|
|
1227
|
-
}
|
|
1228
|
-
function normalizeSetupActionClickCount(input, type, index) {
|
|
1229
|
-
const clickCountInput = valueFromOwn(input, "click_count", "clickCount", "clicks");
|
|
1230
|
-
if (clickCountInput === void 0) return void 0;
|
|
1231
|
-
if (type !== "click") {
|
|
1232
|
-
throw new Error(`target.setup_actions[${index}].click_count is only supported for click actions.`);
|
|
1233
|
-
}
|
|
1234
|
-
const clickCount = numberValue(clickCountInput);
|
|
1235
|
-
if (clickCount === void 0 || !Number.isInteger(clickCount) || clickCount < 1 || clickCount > 10) {
|
|
1236
|
-
throw new Error(`target.setup_actions[${index}].click_count must be an integer from 1 to 10.`);
|
|
1237
|
-
}
|
|
1238
|
-
return clickCount;
|
|
1239
|
-
}
|
|
1240
|
-
function normalizeSetupActionCoordinateMode(value, index) {
|
|
1241
|
-
if (value === void 0 || value === null || value === "") return void 0;
|
|
1242
|
-
const normalized = String(value).trim().replace(/-/g, "_").toLowerCase();
|
|
1243
|
-
if (normalized === "pixels" || normalized === "pixel" || normalized === "px") return "pixels";
|
|
1244
|
-
if (normalized === "ratio" || normalized === "relative" || normalized === "fraction") return "ratio";
|
|
1245
|
-
throw new Error(`target.setup_actions[${index}].coordinate_mode ${String(value)} is not supported. Supported coordinate modes: pixels, ratio.`);
|
|
1246
|
-
}
|
|
1247
|
-
function normalizeSetupActionPointerType(value, type, index) {
|
|
1248
|
-
if (value === void 0 || value === null || value === "") return void 0;
|
|
1249
|
-
if (type !== "drag" && type !== "tap" && type !== "tap_until") {
|
|
1250
|
-
throw new Error(`target.setup_actions[${index}].pointer_type is only supported for drag/tap/tap_until actions.`);
|
|
1251
|
-
}
|
|
1252
|
-
const normalized = String(value).trim().replace(/-/g, "_").toLowerCase();
|
|
1253
|
-
if (normalized === "mouse") return "mouse";
|
|
1254
|
-
if (normalized === "touch" || normalized === "finger") return "touch";
|
|
1255
|
-
if (normalized === "pen" || normalized === "stylus") return "pen";
|
|
1256
|
-
throw new Error(`target.setup_actions[${index}].pointer_type ${String(value)} is not supported. Supported pointer types: mouse, touch, pen.`);
|
|
1257
|
-
}
|
|
1258
|
-
function normalizeSetupActionScreenshotFullPage(input, type, index) {
|
|
1259
|
-
const directFullPage = booleanValue(valueFromOwn(input, "full_page", "fullPage"));
|
|
1260
|
-
const viewportOnly = booleanValue(valueFromOwn(input, "viewport_only", "viewportOnly", "viewport_screenshot", "viewportScreenshot"));
|
|
1261
|
-
if (type !== "screenshot") {
|
|
1262
|
-
if (directFullPage !== void 0 || viewportOnly !== void 0 || valueFromOwn(input, "screenshot_mode", "screenshotMode", "capture_mode", "captureMode") !== void 0) {
|
|
1263
|
-
throw new Error(`target.setup_actions[${index}].full_page is only supported for screenshot actions.`);
|
|
1264
|
-
}
|
|
1265
|
-
return void 0;
|
|
1266
|
-
}
|
|
1267
|
-
const modeInput = stringFromOwn(input, "mode", "screenshot_mode", "screenshotMode", "capture_mode", "captureMode");
|
|
1268
|
-
let modeFullPage;
|
|
1269
|
-
if (modeInput) {
|
|
1270
|
-
const mode = modeInput.trim().toLowerCase().replace(/[-\s]+/g, "_");
|
|
1271
|
-
if (mode === "full_page" || mode === "fullpage" || mode === "page" || mode === "document") {
|
|
1272
|
-
modeFullPage = true;
|
|
1273
|
-
} else if (mode === "viewport" || mode === "view") {
|
|
1274
|
-
modeFullPage = false;
|
|
1275
|
-
} else {
|
|
1276
|
-
throw new Error(`target.setup_actions[${index}].mode ${modeInput} is not supported for screenshot actions. Supported modes: full_page, viewport.`);
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
const values = [directFullPage, viewportOnly === void 0 ? void 0 : !viewportOnly, modeFullPage].filter((value) => value !== void 0);
|
|
1280
|
-
if (!values.length) return void 0;
|
|
1281
|
-
if (values.some((value) => value !== values[0])) {
|
|
1282
|
-
throw new Error(`target.setup_actions[${index}] has conflicting screenshot full_page / viewport mode options.`);
|
|
1283
|
-
}
|
|
1284
|
-
return values[0];
|
|
1285
|
-
}
|
|
1286
|
-
function normalizeSetupActionRandomQueue(input, index) {
|
|
1287
|
-
const rawQueue = valueFromOwn(
|
|
1288
|
-
input,
|
|
1289
|
-
"random_queue",
|
|
1290
|
-
"randomQueue",
|
|
1291
|
-
"random_values",
|
|
1292
|
-
"randomValues",
|
|
1293
|
-
"random_sequence",
|
|
1294
|
-
"randomSequence",
|
|
1295
|
-
"math_random",
|
|
1296
|
-
"mathRandom"
|
|
1297
|
-
);
|
|
1298
|
-
if (rawQueue === void 0) return void 0;
|
|
1299
|
-
if (!Array.isArray(rawQueue) || rawQueue.length === 0) {
|
|
1300
|
-
throw new Error(`target.setup_actions[${index}].random_queue must be a non-empty array of numbers from 0 inclusive to 1 exclusive.`);
|
|
1301
|
-
}
|
|
1302
|
-
return rawQueue.map((item, queueIndex) => {
|
|
1303
|
-
const value = numberValue(item);
|
|
1304
|
-
if (value === void 0 || value < 0 || value >= 1) {
|
|
1305
|
-
throw new Error(`target.setup_actions[${index}].random_queue[${queueIndex}] must be a finite number from 0 inclusive to 1 exclusive.`);
|
|
1306
|
-
}
|
|
1307
|
-
return value;
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
function normalizeSetupActionNonNegativeNumber(input, index, outputKey, ...keys) {
|
|
1311
|
-
const rawValue = valueFromOwn(input, ...keys);
|
|
1312
|
-
if (rawValue === void 0) return void 0;
|
|
1313
|
-
const value = numberValue(rawValue);
|
|
1314
|
-
if (value === void 0 || value < 0) {
|
|
1315
|
-
throw new Error(`target.setup_actions[${index}].${outputKey} must be a finite non-negative number.`);
|
|
1316
|
-
}
|
|
1317
|
-
return value;
|
|
1318
|
-
}
|
|
1319
|
-
function normalizeSetupAction(input, index) {
|
|
1320
|
-
if (!isRecord(input)) throw new Error(`target.setup_actions[${index}] must be an object.`);
|
|
1321
|
-
const type = normalizeSetupActionType(stringValue(input.type), index);
|
|
1322
|
-
const rawType = String(input.type || "").trim().replace(/-/g, "_").toLowerCase();
|
|
1323
|
-
const selector = stringValue(input.selector);
|
|
1324
|
-
const frameSelector = stringFromOwn(input, "frame_selector", "frameSelector", "iframe_selector", "iframeSelector");
|
|
1325
|
-
const frameIndex = numberValue(valueFromOwn(input, "frame_index", "frameIndex", "iframe_index", "iframeIndex"));
|
|
1326
|
-
if (frameIndex !== void 0 && (!Number.isInteger(frameIndex) || frameIndex < 0)) {
|
|
1327
|
-
throw new Error(`target.setup_actions[${index}].frame_index must be a non-negative integer.`);
|
|
1328
|
-
}
|
|
1329
|
-
if ((type === "click" || type === "tap" || type === "tap_until" || type === "drag" || type === "fill" || type === "set_input_value" || type === "set_range_value" || type === "canvas_signature" || type === "wait_for_selector" || type === "wait_for_text" || type === "assert_text_visible" || type === "assert_text_absent" || type === "assert_selector_count") && !selector) {
|
|
1330
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires selector.`);
|
|
1331
|
-
}
|
|
1332
|
-
const fromX = type === "click" || type === "tap" || type === "tap_until" ? numberValue(valueFromOwn(input, "from_x", "fromX", "x", "click_x", "clickX", "start_x", "startX", "x1")) : numberValue(valueFromOwn(input, "from_x", "fromX", "start_x", "startX", "x1"));
|
|
1333
|
-
const fromY = type === "click" || type === "tap" || type === "tap_until" ? numberValue(valueFromOwn(input, "from_y", "fromY", "y", "click_y", "clickY", "start_y", "startY", "y1")) : numberValue(valueFromOwn(input, "from_y", "fromY", "start_y", "startY", "y1"));
|
|
1334
|
-
const toX = numberValue(valueFromOwn(input, "to_x", "toX", "end_x", "endX", "x2"));
|
|
1335
|
-
const toY = numberValue(valueFromOwn(input, "to_y", "toY", "end_y", "endY", "y2"));
|
|
1336
|
-
const coordinateMode = normalizeSetupActionCoordinateMode(valueFromOwn(input, "coordinate_mode", "coordinateMode", "coords", "units"), index);
|
|
1337
|
-
const pointerType = normalizeSetupActionPointerType(valueFromOwn(input, "pointer_type", "pointerType", "input_type", "inputType"), type, index);
|
|
1338
|
-
const durationMs = numberValue(input.duration_ms) ?? numberValue(input.durationMs);
|
|
1339
|
-
const holdMs = type === "press" ? normalizeSetupActionNonNegativeNumber(input, index, "hold_ms", "hold_ms", "holdMs", "key_down_ms", "keyDownMs", "down_ms", "downMs") ?? durationMs : void 0;
|
|
1340
|
-
if (type === "press" && holdMs !== void 0 && (holdMs < 0 || holdMs > 3e4)) {
|
|
1341
|
-
throw new Error(`target.setup_actions[${index}].hold_ms must be a finite number from 0 to 30000.`);
|
|
1342
|
-
}
|
|
1343
|
-
if (type === "click") {
|
|
1344
|
-
const hasClickCoordinate = fromX !== void 0 || fromY !== void 0;
|
|
1345
|
-
if (hasClickCoordinate && (fromX === void 0 || fromY === void 0)) {
|
|
1346
|
-
throw new Error(`target.setup_actions[${index}] click coordinates require both x and y.`);
|
|
1347
|
-
}
|
|
1348
|
-
if (hasClickCoordinate && fromX !== void 0 && fromY !== void 0) {
|
|
1349
|
-
const clickCoordinates = [fromX, fromY];
|
|
1350
|
-
if (coordinateMode === "ratio" && clickCoordinates.some((value2) => value2 < 0 || value2 > 1)) {
|
|
1351
|
-
throw new Error(`target.setup_actions[${index}] click ratio coordinates must be between 0 and 1.`);
|
|
1352
|
-
}
|
|
1353
|
-
if ((coordinateMode === void 0 || coordinateMode === "pixels") && clickCoordinates.some((value2) => value2 < 0)) {
|
|
1354
|
-
throw new Error(`target.setup_actions[${index}] click pixel coordinates must be non-negative.`);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
if (type === "tap" || type === "tap_until") {
|
|
1359
|
-
const hasTapCoordinate = fromX !== void 0 || fromY !== void 0;
|
|
1360
|
-
if (hasTapCoordinate && (fromX === void 0 || fromY === void 0)) {
|
|
1361
|
-
throw new Error(`target.setup_actions[${index}] ${type} coordinates require both x and y.`);
|
|
1362
|
-
}
|
|
1363
|
-
if (hasTapCoordinate && fromX !== void 0 && fromY !== void 0) {
|
|
1364
|
-
const tapCoordinates = [fromX, fromY];
|
|
1365
|
-
if (coordinateMode === "ratio" && tapCoordinates.some((value2) => value2 < 0 || value2 > 1)) {
|
|
1366
|
-
throw new Error(`target.setup_actions[${index}] ${type} ratio coordinates must be between 0 and 1.`);
|
|
1367
|
-
}
|
|
1368
|
-
if ((coordinateMode === void 0 || coordinateMode === "pixels") && tapCoordinates.some((value2) => value2 < 0)) {
|
|
1369
|
-
throw new Error(`target.setup_actions[${index}] ${type} pixel coordinates must be non-negative.`);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
if (type === "drag") {
|
|
1374
|
-
if (fromX === void 0 || fromY === void 0 || toX === void 0 || toY === void 0) {
|
|
1375
|
-
throw new Error(`target.setup_actions[${index}] drag requires from_x, from_y, to_x, and to_y.`);
|
|
1376
|
-
}
|
|
1377
|
-
if (coordinateMode === "ratio" && [fromX, fromY, toX, toY].some((value2) => value2 < 0 || value2 > 1)) {
|
|
1378
|
-
throw new Error(`target.setup_actions[${index}] drag ratio coordinates must be between 0 and 1.`);
|
|
1379
|
-
}
|
|
1380
|
-
if ((coordinateMode === void 0 || coordinateMode === "pixels") && [fromX, fromY, toX, toY].some((value2) => value2 < 0)) {
|
|
1381
|
-
throw new Error(`target.setup_actions[${index}] drag pixel coordinates must be non-negative.`);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
if (type === "wait_for_text" && !stringValue(input.text) && !stringValue(input.pattern)) {
|
|
1385
|
-
throw new Error(`target.setup_actions[${index}] wait_for_text requires text or pattern.`);
|
|
1386
|
-
}
|
|
1387
|
-
if ((type === "assert_text_visible" || type === "assert_text_absent") && !stringValue(input.text) && !stringValue(input.pattern)) {
|
|
1388
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires text or pattern.`);
|
|
1389
|
-
}
|
|
1390
|
-
const expectedCount = numberValue(input.expected_count ?? input.expectedCount ?? input.count);
|
|
1391
|
-
if (type === "assert_selector_count" && (expectedCount === void 0 || !Number.isInteger(expectedCount) || expectedCount < 0)) {
|
|
1392
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires non-negative integer expected_count.`);
|
|
1393
|
-
}
|
|
1394
|
-
const value = stringFromOwn(input, "value", "input_value", "inputValue");
|
|
1395
|
-
const hasJsonValue = hasOwn(input, "value_json") || hasOwn(input, "valueJson") || hasOwn(input, "json");
|
|
1396
|
-
if ((type === "fill" || type === "set_input_value" || type === "set_range_value") && value === void 0 && !hasJsonValue) {
|
|
1397
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires value.`);
|
|
1398
|
-
}
|
|
1399
|
-
const randomQueue = type === "deterministic_runtime" ? normalizeSetupActionRandomQueue(input, index) : void 0;
|
|
1400
|
-
const deterministicNow = type === "deterministic_runtime" ? normalizeSetupActionNonNegativeNumber(input, index, "now", "now", "date_now", "dateNow", "mock_now", "mockNow", "clock", "timestamp", "time_ms", "timeMs") : void 0;
|
|
1401
|
-
const deterministicAdvanceMs = type === "deterministic_runtime" ? normalizeSetupActionNonNegativeNumber(input, index, "advance_ms", "advance_ms", "advanceMs", "tick_ms", "tickMs", "add_ms", "addMs") : void 0;
|
|
1402
|
-
const deterministicAppend = type === "deterministic_runtime" && booleanValue(valueFromOwn(input, "append", "append_random", "appendRandom")) === true;
|
|
1403
|
-
const deterministicRestore = type === "deterministic_runtime" && booleanValue(valueFromOwn(input, "restore", "reset", "restore_originals", "restoreOriginals")) === true;
|
|
1404
|
-
if (type === "deterministic_runtime" && randomQueue === void 0 && deterministicNow === void 0 && deterministicAdvanceMs === void 0 && !deterministicRestore) {
|
|
1405
|
-
throw new Error(`target.setup_actions[${index}] deterministic_runtime requires random_queue, now, advance_ms, or restore.`);
|
|
1406
|
-
}
|
|
1407
|
-
const key = stringValue(input.key);
|
|
1408
|
-
let dialogAccept;
|
|
1409
|
-
if (type === "dialog_response") {
|
|
1410
|
-
const acceptInput = valueFromOwn(input, "accept", "accepted", "should_accept", "shouldAccept");
|
|
1411
|
-
const responseInput = stringFromOwn(input, "response", "dialog_response", "dialogResponse", "mode");
|
|
1412
|
-
const response = String(responseInput || "").trim().toLowerCase().replace(/-/g, "_");
|
|
1413
|
-
if (acceptInput !== void 0) {
|
|
1414
|
-
dialogAccept = acceptInput !== false && String(acceptInput).toLowerCase() !== "false";
|
|
1415
|
-
} else if (rawType === "dismiss_dialog" || rawType === "dismiss_dialogs" || rawType === "cancel_dialog") {
|
|
1416
|
-
dialogAccept = false;
|
|
1417
|
-
} else if (response === "dismiss" || response === "cancel" || response === "reject" || response === "no" || response === "false") {
|
|
1418
|
-
dialogAccept = false;
|
|
1419
|
-
} else {
|
|
1420
|
-
dialogAccept = true;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
if ((type === "press" || type === "key_down" || type === "key_up") && !key) {
|
|
1424
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires key.`);
|
|
1425
|
-
}
|
|
1426
|
-
if ((type === "local_storage" || type === "session_storage") && !key) {
|
|
1427
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires key.`);
|
|
1428
|
-
}
|
|
1429
|
-
if ((type === "local_storage" || type === "session_storage") && value === void 0 && !hasJsonValue) {
|
|
1430
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires value.`);
|
|
1431
|
-
}
|
|
1432
|
-
const path = stringFromOwn(input, "path", "function_path", "functionPath", "window_path", "windowPath", "state_path", "statePath");
|
|
1433
|
-
if ((type === "window_call" || type === "window_call_until" || type === "assert_window_value" || type === "assert_window_number") && !path) {
|
|
1434
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires path.`);
|
|
1435
|
-
}
|
|
1436
|
-
const script = stringFromOwn(input, "script", "code", "source", "body");
|
|
1437
|
-
if (type === "window_eval" && !script) {
|
|
1438
|
-
throw new Error(`target.setup_actions[${index}] window_eval requires script.`);
|
|
1439
|
-
}
|
|
1440
|
-
const args = type === "window_call" || type === "window_call_until" || type === "window_eval" ? normalizeSetupActionArgs(input, index) : void 0;
|
|
1441
|
-
const hasExpectedValue = hasOwn(input, "expected_value") || hasOwn(input, "expectedValue") || hasOwn(input, "expected") || hasOwn(input, "expect_value") || hasOwn(input, "expectValue") || hasOwn(input, "expect");
|
|
1442
|
-
if (type === "assert_window_value" && !hasExpectedValue) {
|
|
1443
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires expected_value.`);
|
|
1444
|
-
}
|
|
1445
|
-
const rawExpectedValue = valueFromOwn(input, "expected_value", "expectedValue", "expected", "expect_value", "expectValue", "expect");
|
|
1446
|
-
const minValue = numberValue(valueFromOwn(input, "min_value", "minValue", "minimum", "min", "at_least", "atLeast", "gte"));
|
|
1447
|
-
const maxValue = numberValue(valueFromOwn(input, "max_value", "maxValue", "maximum", "max", "at_most", "atMost", "lte"));
|
|
1448
|
-
if (type === "assert_window_number") {
|
|
1449
|
-
if (!hasExpectedValue && minValue === void 0 && maxValue === void 0) {
|
|
1450
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires expected_value, min_value, or max_value.`);
|
|
1451
|
-
}
|
|
1452
|
-
if (hasExpectedValue && numberValue(rawExpectedValue) === void 0) {
|
|
1453
|
-
throw new Error(`target.setup_actions[${index}] ${type} expected_value must be a finite number.`);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
const hasExpectedReturn = hasOwn(input, "expect_return") || hasOwn(input, "expectReturn") || hasOwn(input, "expected_return") || hasOwn(input, "expectedReturn");
|
|
1457
|
-
const storeReturnTo = stringFromOwn(
|
|
1458
|
-
input,
|
|
1459
|
-
"store_return_to",
|
|
1460
|
-
"storeReturnTo",
|
|
1461
|
-
"save_return_to",
|
|
1462
|
-
"saveReturnTo",
|
|
1463
|
-
"assign_return_to",
|
|
1464
|
-
"assignReturnTo",
|
|
1465
|
-
"return_state_path",
|
|
1466
|
-
"returnStatePath",
|
|
1467
|
-
"store_signature_to",
|
|
1468
|
-
"storeSignatureTo",
|
|
1469
|
-
"signature_path",
|
|
1470
|
-
"signaturePath"
|
|
1471
|
-
);
|
|
1472
|
-
const captureReturn = input.capture_return === false || input.captureReturn === false || input.include_return === false || input.includeReturn === false || input.omit_return === true || input.omitReturn === true ? false : void 0;
|
|
1473
|
-
const untilPath = stringFromOwn(input, "until_path", "untilPath", "until_state_path", "untilStatePath", "until_window_path", "untilWindowPath", "until");
|
|
1474
|
-
const hasUntilExpectedValue = hasOwn(input, "until_expected_value") || hasOwn(input, "untilExpectedValue") || hasOwn(input, "until_expected") || hasOwn(input, "untilExpected") || hasOwn(input, "until_value") || hasOwn(input, "untilValue") || hasOwn(input, "expected_value") || hasOwn(input, "expectedValue") || hasOwn(input, "expected");
|
|
1475
|
-
if (type === "window_call_until" || type === "tap_until") {
|
|
1476
|
-
if (!untilPath) {
|
|
1477
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires until_path.`);
|
|
1478
|
-
}
|
|
1479
|
-
if (!hasUntilExpectedValue) {
|
|
1480
|
-
throw new Error(`target.setup_actions[${index}] ${type} requires until_expected_value.`);
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
const maxCalls = numberValue(valueFromOwn(input, "max_calls", "maxCalls", "max_attempts", "maxAttempts", "attempts", "max_taps", "maxTaps", "tap_limit", "tapLimit"));
|
|
1484
|
-
if ((type === "window_call_until" || type === "tap_until") && (maxCalls === void 0 || !Number.isInteger(maxCalls) || maxCalls < 1 || maxCalls > 100)) {
|
|
1485
|
-
throw new Error(`target.setup_actions[${index}].max_calls must be an integer from 1 to 100.`);
|
|
1486
|
-
}
|
|
1487
|
-
const tapBurstSize = type === "tap_until" ? numberValue(valueFromOwn(input, "tap_burst_size", "tapBurstSize", "burst_size", "burstSize", "check_every_taps", "checkEveryTaps", "predicate_interval_taps", "predicateIntervalTaps")) : void 0;
|
|
1488
|
-
if (type === "tap_until" && tapBurstSize !== void 0 && (!Number.isInteger(tapBurstSize) || tapBurstSize < 1 || tapBurstSize > 100)) {
|
|
1489
|
-
throw new Error(`target.setup_actions[${index}].tap_burst_size must be an integer from 1 to 100.`);
|
|
1490
|
-
}
|
|
1491
|
-
const settleMs = type === "tap_until" ? numberValue(valueFromOwn(input, "settle_ms", "settleMs", "predicate_settle_ms", "predicateSettleMs", "post_burst_wait_ms", "postBurstWaitMs", "after_burst_ms", "afterBurstMs", "settle_after_tap_ms", "settleAfterTapMs")) : void 0;
|
|
1492
|
-
if (type === "tap_until" && settleMs !== void 0 && (!Number.isInteger(settleMs) || settleMs < 0 || settleMs > 1e4)) {
|
|
1493
|
-
throw new Error(`target.setup_actions[${index}].settle_ms must be an integer from 0 to 10000.`);
|
|
1494
|
-
}
|
|
1495
|
-
const intervalMs = numberValue(valueFromOwn(input, "interval_ms", "intervalMs", "poll_ms", "pollMs", "call_interval_ms", "callIntervalMs"));
|
|
1496
|
-
if ((type === "window_call_until" || type === "tap_until") && intervalMs !== void 0 && (!Number.isInteger(intervalMs) || intervalMs < 0 || intervalMs > 5e3)) {
|
|
1497
|
-
throw new Error(`target.setup_actions[${index}].interval_ms must be an integer from 0 to 5000.`);
|
|
1498
|
-
}
|
|
1499
|
-
const steps = numberValue(input.steps);
|
|
1500
|
-
if (type === "drag" && steps !== void 0 && (!Number.isInteger(steps) || steps < 1 || steps > 100)) {
|
|
1501
|
-
throw new Error(`target.setup_actions[${index}].steps must be an integer from 1 to 100.`);
|
|
1502
|
-
}
|
|
1503
|
-
return {
|
|
1504
|
-
type,
|
|
1505
|
-
selector,
|
|
1506
|
-
frame_selector: frameSelector,
|
|
1507
|
-
frame_index: frameIndex,
|
|
1508
|
-
full_page: normalizeSetupActionScreenshotFullPage(input, type, index),
|
|
1509
|
-
force: type === "click" && (input.force === true || input.force_click === true || input.forceClick === true),
|
|
1510
|
-
fallback_to_tap: type === "click" && (input.fallback_to_tap === true || input.fallbackToTap === true || input.fallback_to_pointer_tap === true || input.fallbackToPointerTap === true || input.pointer_fallback === true || input.pointerFallback === true) || void 0,
|
|
1511
|
-
click_count: normalizeSetupActionClickCount(input, type, index),
|
|
1512
|
-
coordinate_mode: coordinateMode,
|
|
1513
|
-
pointer_type: pointerType,
|
|
1514
|
-
from_x: fromX,
|
|
1515
|
-
from_y: fromY,
|
|
1516
|
-
to_x: toX,
|
|
1517
|
-
to_y: toY,
|
|
1518
|
-
duration_ms: durationMs,
|
|
1519
|
-
steps,
|
|
1520
|
-
key,
|
|
1521
|
-
hold_ms: holdMs,
|
|
1522
|
-
value,
|
|
1523
|
-
value_json: hasJsonValue ? toJsonValue(input.value_json ?? input.valueJson ?? input.json) : void 0,
|
|
1524
|
-
random_queue: randomQueue,
|
|
1525
|
-
now: deterministicNow,
|
|
1526
|
-
advance_ms: deterministicAdvanceMs,
|
|
1527
|
-
append: deterministicAppend || void 0,
|
|
1528
|
-
restore: deterministicRestore || void 0,
|
|
1529
|
-
label: stringFromOwn(input, "label", "name", "screenshot_label", "screenshotLabel"),
|
|
1530
|
-
script,
|
|
1531
|
-
path,
|
|
1532
|
-
args,
|
|
1533
|
-
expect_return: hasExpectedReturn ? toJsonValue(valueFromOwn(input, "expect_return", "expectReturn", "expected_return", "expectedReturn")) : void 0,
|
|
1534
|
-
store_return_to: storeReturnTo,
|
|
1535
|
-
capture_return: captureReturn,
|
|
1536
|
-
return_summary_fields: normalizeReturnSummaryFields(input, index),
|
|
1537
|
-
compare_to: stringFromOwn(input, "compare_to", "compareTo", "previous_signature_path", "previousSignaturePath", "previous_path", "previousPath", "changed_from", "changedFrom"),
|
|
1538
|
-
expect_changed: booleanValue(valueFromOwn(input, "expect_changed", "expectChanged", "should_change", "shouldChange", "changed")),
|
|
1539
|
-
until_path: untilPath,
|
|
1540
|
-
until_expected_value: hasUntilExpectedValue ? toJsonValue(valueFromOwn(input, "until_expected_value", "untilExpectedValue", "until_expected", "untilExpected", "until_value", "untilValue", "expected_value", "expectedValue", "expected")) : void 0,
|
|
1541
|
-
expected_path: stringFromOwn(input, "expected_path", "expectedPath", "expected_terminal_path", "expectedTerminalPath"),
|
|
1542
|
-
expected_url: stringFromOwn(input, "expected_url", "expectedUrl", "expected_terminal_url", "expectedTerminalUrl"),
|
|
1543
|
-
max_calls: maxCalls,
|
|
1544
|
-
tap_burst_size: tapBurstSize,
|
|
1545
|
-
settle_ms: settleMs,
|
|
1546
|
-
interval_ms: intervalMs,
|
|
1547
|
-
expected_value: hasExpectedValue ? toJsonValue(rawExpectedValue) : void 0,
|
|
1548
|
-
min_value: minValue,
|
|
1549
|
-
max_value: maxValue,
|
|
1550
|
-
text: stringValue(input.text),
|
|
1551
|
-
pattern: stringValue(input.pattern),
|
|
1552
|
-
flags: stringValue(input.flags),
|
|
1553
|
-
accept: dialogAccept,
|
|
1554
|
-
prompt_text: stringFromOwn(input, "prompt_text", "promptText", "prompt_value", "promptValue"),
|
|
1555
|
-
message_text: stringFromOwn(input, "message_text", "messageText", "dialog_text", "dialogText"),
|
|
1556
|
-
message_pattern: stringFromOwn(input, "message_pattern", "messagePattern", "dialog_pattern", "dialogPattern"),
|
|
1557
|
-
index: numberValue(valueFromOwn(input, "index", "target_index", "targetIndex")),
|
|
1558
|
-
expected_count: expectedCount,
|
|
1559
|
-
ms: numberValue(input.ms) ?? numberValue(input.wait_ms) ?? numberValue(input.waitMs),
|
|
1560
|
-
timeout_ms: numberValue(input.timeout_ms) ?? numberValue(input.timeoutMs),
|
|
1561
|
-
after_ms: numberValue(input.after_ms) ?? numberValue(input.afterMs),
|
|
1562
|
-
repeat: normalizeSetupActionRepeat(input, index),
|
|
1563
|
-
reload: input.reload === true,
|
|
1564
|
-
storage: normalizeSetupActionStorage(input.storage, index),
|
|
1565
|
-
viewports: normalizeStringList(input.viewports ?? input.viewport_names ?? input.viewportNames, `target.setup_actions[${index}] viewports`),
|
|
1566
|
-
optional: input.optional === true || input.required === false,
|
|
1567
|
-
continue_on_failure: input.continue_on_failure === true || input.continueOnFailure === true
|
|
1568
|
-
};
|
|
1569
|
-
}
|
|
1570
|
-
function normalizeSetupActions(value) {
|
|
1571
|
-
if (value === void 0) return void 0;
|
|
1572
|
-
if (!Array.isArray(value)) throw new Error("target.setup_actions must be an array.");
|
|
1573
|
-
return value.map(normalizeSetupAction);
|
|
1574
|
-
}
|
|
1575
|
-
function normalizeTargetScreenshotFullPage(input) {
|
|
1576
|
-
const directFullPage = booleanValue(valueFromOwn(
|
|
1577
|
-
input,
|
|
1578
|
-
"screenshot_full_page",
|
|
1579
|
-
"screenshotFullPage",
|
|
1580
|
-
"final_screenshot_full_page",
|
|
1581
|
-
"finalScreenshotFullPage",
|
|
1582
|
-
"full_page_screenshots",
|
|
1583
|
-
"fullPageScreenshots"
|
|
1584
|
-
));
|
|
1585
|
-
const viewportOnly = booleanValue(valueFromOwn(
|
|
1586
|
-
input,
|
|
1587
|
-
"viewport_screenshots",
|
|
1588
|
-
"viewportScreenshots",
|
|
1589
|
-
"viewport_only_screenshots",
|
|
1590
|
-
"viewportOnlyScreenshots"
|
|
1591
|
-
));
|
|
1592
|
-
const modeInput = stringFromOwn(input, "screenshot_mode", "screenshotMode", "final_screenshot_mode", "finalScreenshotMode");
|
|
1593
|
-
let modeFullPage;
|
|
1594
|
-
if (modeInput) {
|
|
1595
|
-
const mode = modeInput.trim().toLowerCase().replace(/[-\s]+/g, "_");
|
|
1596
|
-
if (mode === "full_page" || mode === "fullpage" || mode === "page" || mode === "document") {
|
|
1597
|
-
modeFullPage = true;
|
|
1598
|
-
} else if (mode === "viewport" || mode === "view") {
|
|
1599
|
-
modeFullPage = false;
|
|
1600
|
-
} else {
|
|
1601
|
-
throw new Error(`target.screenshot_mode ${modeInput} is not supported. Supported modes: full_page, viewport.`);
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
const values = [directFullPage, viewportOnly === void 0 ? void 0 : !viewportOnly, modeFullPage].filter((value) => value !== void 0);
|
|
1605
|
-
if (!values.length) return void 0;
|
|
1606
|
-
if (values.some((value) => value !== values[0])) {
|
|
1607
|
-
throw new Error("target has conflicting screenshot full_page / viewport mode options.");
|
|
1608
|
-
}
|
|
1609
|
-
return values[0];
|
|
1610
|
-
}
|
|
1611
|
-
function normalizeNetworkMock(input, index) {
|
|
1612
|
-
if (!isRecord(input)) throw new Error(`target.network_mocks[${index}] must be an object.`);
|
|
1613
|
-
const url = stringValue(input.url) || stringValue(input.glob) || stringValue(input.pattern);
|
|
1614
|
-
if (!url) throw new Error(`target.network_mocks[${index}] requires url.`);
|
|
1615
|
-
const payload = normalizeNetworkMockResponsePayload(input, `target.network_mocks[${index}]`);
|
|
1616
|
-
const responsesInput = input.responses ?? input.sequence;
|
|
1617
|
-
const responses = normalizeNetworkMockResponses(responsesInput, index, payload);
|
|
1618
|
-
const requestBody = normalizeNetworkMockRequestBodyConstraints(input, `target.network_mocks[${index}]`);
|
|
1619
|
-
const requiredHitCount = numberValue(
|
|
1620
|
-
input.required_hit_count ?? input.requiredHitCount ?? input.required_hits ?? input.requiredHits ?? input.min_hits ?? input.minHits
|
|
1621
|
-
);
|
|
1622
|
-
if (requiredHitCount !== void 0 && (!Number.isInteger(requiredHitCount) || requiredHitCount < 1)) {
|
|
1623
|
-
throw new Error(`target.network_mocks[${index}].required_hit_count must be a positive integer.`);
|
|
1624
|
-
}
|
|
1625
|
-
const forbidden = input.forbidden === true || input.must_not_hit === true || input.mustNotHit === true || input.should_not_run === true || input.shouldNotRun === true;
|
|
1626
|
-
const configuredMaxHitCount = numberValue(
|
|
1627
|
-
input.max_hit_count ?? input.maxHitCount ?? input.max_hits ?? input.maxHits
|
|
1628
|
-
);
|
|
1629
|
-
if (configuredMaxHitCount !== void 0 && (!Number.isInteger(configuredMaxHitCount) || configuredMaxHitCount < 0)) {
|
|
1630
|
-
throw new Error(`target.network_mocks[${index}].max_hit_count must be a non-negative integer.`);
|
|
1631
|
-
}
|
|
1632
|
-
if (forbidden && configuredMaxHitCount !== void 0 && configuredMaxHitCount !== 0) {
|
|
1633
|
-
throw new Error(`target.network_mocks[${index}].forbidden cannot be combined with max_hit_count greater than 0.`);
|
|
1634
|
-
}
|
|
1635
|
-
const maxHitCount = forbidden ? 0 : configuredMaxHitCount;
|
|
1636
|
-
const required = input.required === false || maxHitCount === 0 && input.required !== true ? false : true;
|
|
1637
|
-
const effectiveRequiredHitCount = required ? requiredHitCount ?? (Array.isArray(responses) && responses.length ? responses.length : 1) : 0;
|
|
1638
|
-
if (maxHitCount !== void 0 && effectiveRequiredHitCount > maxHitCount) {
|
|
1639
|
-
throw new Error(`target.network_mocks[${index}].max_hit_count cannot be less than its required hit count.`);
|
|
1640
|
-
}
|
|
1641
|
-
const sequenceScopeInput = stringValue(
|
|
1642
|
-
input.sequence_scope ?? input.sequenceScope ?? input.response_sequence_scope ?? input.responseSequenceScope
|
|
1643
|
-
);
|
|
1644
|
-
let sequenceScope;
|
|
1645
|
-
if (sequenceScopeInput) {
|
|
1646
|
-
const normalizedScope = sequenceScopeInput.toLowerCase().replace(/[-\s]+/g, "_");
|
|
1647
|
-
if (normalizedScope === "global" || normalizedScope === "profile" || normalizedScope === "run") {
|
|
1648
|
-
sequenceScope = "global";
|
|
1649
|
-
} else if (normalizedScope === "viewport" || normalizedScope === "per_viewport" || normalizedScope === "viewport_scoped") {
|
|
1650
|
-
sequenceScope = "viewport";
|
|
1651
|
-
} else {
|
|
1652
|
-
throw new Error(`target.network_mocks[${index}].sequence_scope must be "global" or "viewport".`);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
return {
|
|
1656
|
-
...payload,
|
|
1657
|
-
label: normalizeName(input.label || input.name, `network-mock-${index + 1}`),
|
|
1658
|
-
url,
|
|
1659
|
-
method: stringValue(input.method)?.toUpperCase(),
|
|
1660
|
-
responses,
|
|
1661
|
-
repeat_responses: input.repeat_responses === true || input.repeatResponses === true || input.cycle_responses === true || input.cycleResponses === true,
|
|
1662
|
-
sequence_scope: sequenceScope,
|
|
1663
|
-
required_hit_count: requiredHitCount,
|
|
1664
|
-
max_hit_count: maxHitCount,
|
|
1665
|
-
forbidden,
|
|
1666
|
-
required,
|
|
1667
|
-
capture_request_body: requestBody.capture_request_body,
|
|
1668
|
-
request_body_contains: requestBody.request_body_contains,
|
|
1669
|
-
request_body_patterns: requestBody.request_body_patterns,
|
|
1670
|
-
request_body_not_contains: requestBody.request_body_not_contains,
|
|
1671
|
-
request_body_not_patterns: requestBody.request_body_not_patterns
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
function normalizeNetworkMockRequestBodyConstraints(input, label) {
|
|
1675
|
-
const requestBodyContains = normalizeStringList(
|
|
1676
|
-
input.request_body_contains ?? input.requestBodyContains ?? input.body_contains ?? input.bodyContains,
|
|
1677
|
-
`${label}.request_body_contains`
|
|
1678
|
-
);
|
|
1679
|
-
const requestBodyPatterns = normalizeStringList(
|
|
1680
|
-
input.request_body_patterns ?? input.requestBodyPatterns ?? input.body_patterns ?? input.bodyPatterns,
|
|
1681
|
-
`${label}.request_body_patterns`
|
|
1682
|
-
);
|
|
1683
|
-
validateRegexPatterns(requestBodyPatterns, `${label}.request_body_patterns`);
|
|
1684
|
-
const requestBodyNotContains = normalizeStringList(
|
|
1685
|
-
input.request_body_not_contains ?? input.requestBodyNotContains ?? input.request_body_absent ?? input.requestBodyAbsent ?? input.body_not_contains ?? input.bodyNotContains ?? input.body_absent ?? input.bodyAbsent,
|
|
1686
|
-
`${label}.request_body_not_contains`
|
|
1687
|
-
);
|
|
1688
|
-
const requestBodyNotPatterns = normalizeStringList(
|
|
1689
|
-
input.request_body_not_patterns ?? input.requestBodyNotPatterns ?? input.request_body_forbidden_patterns ?? input.requestBodyForbiddenPatterns ?? input.body_not_patterns ?? input.bodyNotPatterns ?? input.body_forbidden_patterns ?? input.bodyForbiddenPatterns,
|
|
1690
|
-
`${label}.request_body_not_patterns`
|
|
1691
|
-
);
|
|
1692
|
-
validateRegexPatterns(requestBodyNotPatterns, `${label}.request_body_not_patterns`);
|
|
1693
|
-
return {
|
|
1694
|
-
capture_request_body: input.capture_request_body === true || input.captureRequestBody === true || Boolean(requestBodyContains?.length) || Boolean(requestBodyPatterns?.length) || Boolean(requestBodyNotContains?.length) || Boolean(requestBodyNotPatterns?.length),
|
|
1695
|
-
request_body_contains: requestBodyContains,
|
|
1696
|
-
request_body_patterns: requestBodyPatterns,
|
|
1697
|
-
request_body_not_contains: requestBodyNotContains,
|
|
1698
|
-
request_body_not_patterns: requestBodyNotPatterns
|
|
1699
|
-
};
|
|
1700
|
-
}
|
|
1701
|
-
function normalizeNetworkMockResponsePayload(input, label, defaults = {}) {
|
|
1702
|
-
const status = numberValue(input.status) ?? defaults.status ?? 200;
|
|
1703
|
-
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
1704
|
-
throw new Error(`${label}.status must be an HTTP status code.`);
|
|
1705
|
-
}
|
|
1706
|
-
const body = stringValue(input.body) ?? stringValue(input.body_text) ?? stringValue(input.bodyText) ?? defaults.body;
|
|
1707
|
-
const hasJsonBody = Object.prototype.hasOwnProperty.call(input, "body_json") || Object.prototype.hasOwnProperty.call(input, "bodyJson") || Object.prototype.hasOwnProperty.call(input, "json");
|
|
1708
|
-
const requestBody = normalizeNetworkMockRequestBodyConstraints(input, label);
|
|
1709
|
-
const abort = normalizeNetworkMockAbort(input, label, defaults.abort, defaults.abort_error_code);
|
|
1710
|
-
return {
|
|
1711
|
-
label: stringValue(input.label) || stringValue(input.name) || defaults.label,
|
|
1712
|
-
status,
|
|
1713
|
-
content_type: stringValue(input.content_type) || stringValue(input.contentType) || defaults.content_type,
|
|
1714
|
-
headers: stringRecord(input.headers) || defaults.headers,
|
|
1715
|
-
body,
|
|
1716
|
-
body_json: hasJsonBody ? toJsonValue(input.body_json ?? input.bodyJson ?? input.json) : defaults.body_json,
|
|
1717
|
-
delay_ms: normalizeNetworkMockDelay(input, label, defaults.delay_ms),
|
|
1718
|
-
abort: abort.abort,
|
|
1719
|
-
abort_error_code: abort.abort_error_code,
|
|
1720
|
-
capture_request_body: requestBody.capture_request_body,
|
|
1721
|
-
request_body_contains: requestBody.request_body_contains,
|
|
1722
|
-
request_body_patterns: requestBody.request_body_patterns,
|
|
1723
|
-
request_body_not_contains: requestBody.request_body_not_contains,
|
|
1724
|
-
request_body_not_patterns: requestBody.request_body_not_patterns
|
|
1725
|
-
};
|
|
1726
|
-
}
|
|
1727
|
-
function normalizeNetworkMockAbort(input, label, defaultAbort, defaultErrorCode) {
|
|
1728
|
-
const abortInput = input.abort ?? input.route_abort ?? input.routeAbort;
|
|
1729
|
-
const explicitAbort = typeof abortInput === "string" ? abortInput.trim().length > 0 : abortInput === true;
|
|
1730
|
-
const abort = explicitAbort || defaultAbort === true;
|
|
1731
|
-
if (!abort) return {};
|
|
1732
|
-
const codeInput = stringValue(
|
|
1733
|
-
typeof abortInput === "string" ? abortInput : input.abort_error_code ?? input.abortErrorCode ?? input.abort_error ?? input.abortError ?? input.network_error ?? input.networkError
|
|
1734
|
-
) || defaultErrorCode || "failed";
|
|
1735
|
-
const abort_error_code = codeInput.toLowerCase();
|
|
1736
|
-
if (!RIDDLE_PROOF_PROFILE_NETWORK_ABORT_ERROR_CODES.includes(abort_error_code)) {
|
|
1737
|
-
throw new Error(`${label}.abort_error_code must be one of ${RIDDLE_PROOF_PROFILE_NETWORK_ABORT_ERROR_CODES.join(", ")}.`);
|
|
1738
|
-
}
|
|
1739
|
-
return { abort: true, abort_error_code };
|
|
1740
|
-
}
|
|
1741
|
-
function normalizeNetworkMockDelay(input, label, defaultValue) {
|
|
1742
|
-
const value = numberValue(
|
|
1743
|
-
input.delay_ms ?? input.delayMs ?? input.wait_ms ?? input.waitMs ?? input.latency_ms ?? input.latencyMs
|
|
1744
|
-
) ?? defaultValue;
|
|
1745
|
-
if (value === void 0) return void 0;
|
|
1746
|
-
if (!Number.isInteger(value) || value < 0 || value > 6e4) {
|
|
1747
|
-
throw new Error(`${label}.delay_ms must be an integer from 0 to 60000.`);
|
|
1748
|
-
}
|
|
1749
|
-
return value;
|
|
1750
|
-
}
|
|
1751
|
-
function normalizeNetworkMockResponses(value, mockIndex, defaults) {
|
|
1752
|
-
if (value === void 0) return void 0;
|
|
1753
|
-
if (!Array.isArray(value)) throw new Error(`target.network_mocks[${mockIndex}].responses must be an array.`);
|
|
1754
|
-
if (!value.length) throw new Error(`target.network_mocks[${mockIndex}].responses must not be empty.`);
|
|
1755
|
-
const responseDefaults = {
|
|
1756
|
-
label: void 0,
|
|
1757
|
-
status: defaults.status,
|
|
1758
|
-
content_type: defaults.content_type,
|
|
1759
|
-
headers: defaults.headers,
|
|
1760
|
-
body: defaults.body,
|
|
1761
|
-
body_json: defaults.body_json,
|
|
1762
|
-
delay_ms: defaults.delay_ms,
|
|
1763
|
-
abort: defaults.abort,
|
|
1764
|
-
abort_error_code: defaults.abort_error_code
|
|
1765
|
-
};
|
|
1766
|
-
return value.map((response, responseIndex) => {
|
|
1767
|
-
if (!isRecord(response)) {
|
|
1768
|
-
throw new Error(`target.network_mocks[${mockIndex}].responses[${responseIndex}] must be an object.`);
|
|
1769
|
-
}
|
|
1770
|
-
return normalizeNetworkMockResponsePayload(
|
|
1771
|
-
response,
|
|
1772
|
-
`target.network_mocks[${mockIndex}].responses[${responseIndex}]`,
|
|
1773
|
-
responseDefaults
|
|
1774
|
-
);
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
|
-
function normalizeNetworkMocks(value) {
|
|
1778
|
-
if (value === void 0) return void 0;
|
|
1779
|
-
if (!Array.isArray(value)) throw new Error("target.network_mocks must be an array.");
|
|
1780
|
-
return value.map(normalizeNetworkMock);
|
|
1781
|
-
}
|
|
1782
|
-
function profileStringList(value) {
|
|
1783
|
-
return Array.isArray(value) ? value.map((item) => String(item)).filter(Boolean) : [];
|
|
1784
|
-
}
|
|
1785
|
-
function responseHasRequestBodyContract(response) {
|
|
1786
|
-
if (!response) return false;
|
|
1787
|
-
return profileStringList(response.request_body_contains).length > 0 || profileStringList(response.request_body_patterns).length > 0 || profileStringList(response.request_body_not_contains).length > 0 || profileStringList(response.request_body_not_patterns).length > 0;
|
|
1788
|
-
}
|
|
1789
|
-
function responseHasOnlyPositiveTextSelector(response) {
|
|
1790
|
-
if (!response) return false;
|
|
1791
|
-
return profileStringList(response.request_body_contains).length > 0 && profileStringList(response.request_body_patterns).length === 0 && profileStringList(response.request_body_not_contains).length === 0 && profileStringList(response.request_body_not_patterns).length === 0;
|
|
1792
|
-
}
|
|
1793
|
-
function responseMayShadowLaterRequestBodyMatch(earlier, later) {
|
|
1794
|
-
if (!responseHasOnlyPositiveTextSelector(earlier) || !responseHasRequestBodyContract(later)) return false;
|
|
1795
|
-
const earlierContains = profileStringList(earlier.request_body_contains);
|
|
1796
|
-
const laterContains = profileStringList(later.request_body_contains);
|
|
1797
|
-
if (!laterContains.length) return false;
|
|
1798
|
-
return earlierContains.every((fragment) => laterContains.includes(fragment));
|
|
1799
|
-
}
|
|
1800
|
-
function responseLabel(response, index) {
|
|
1801
|
-
return response.label ? `"${response.label}"` : `responses[${index}]`;
|
|
1802
|
-
}
|
|
1803
|
-
function collectRiddleProofProfileWarnings(profile) {
|
|
1804
|
-
const warnings = [];
|
|
1805
|
-
for (const [mockIndex, mock] of (profile.target.network_mocks || []).entries()) {
|
|
1806
|
-
const responses = Array.isArray(mock.responses) ? mock.responses : [];
|
|
1807
|
-
if (responses.length < 2) continue;
|
|
1808
|
-
for (let laterIndex = 1; laterIndex < responses.length; laterIndex += 1) {
|
|
1809
|
-
const later = responses[laterIndex];
|
|
1810
|
-
if (!responseHasRequestBodyContract(later)) continue;
|
|
1811
|
-
for (let earlierIndex = 0; earlierIndex < laterIndex; earlierIndex += 1) {
|
|
1812
|
-
const earlier = responses[earlierIndex];
|
|
1813
|
-
if (!responseMayShadowLaterRequestBodyMatch(earlier, later)) continue;
|
|
1814
|
-
const mockLabel = mock.label ? ` (${mock.label})` : "";
|
|
1815
|
-
warnings.push(
|
|
1816
|
-
`target.network_mocks[${mockIndex}]${mockLabel} ${responseLabel(earlier, earlierIndex)} can shadow ${responseLabel(later, laterIndex)} because the earlier request_body_contains fragments are a subset of the later response and have no negative or pattern disambiguator. First matching request-body response wins.`
|
|
1817
|
-
);
|
|
1818
|
-
break;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
return warnings;
|
|
1823
|
-
}
|
|
1824
|
-
function profileStatusProbeCounts(profile) {
|
|
1825
|
-
let httpStatus = 0;
|
|
1826
|
-
let linkStatus = 0;
|
|
1827
|
-
for (const check of profile.checks || []) {
|
|
1828
|
-
if (check.type === "http_status") httpStatus += 1;
|
|
1829
|
-
if (check.type === "link_status" || check.type === "artifact_link_status") linkStatus += 1;
|
|
1830
|
-
}
|
|
1831
|
-
return { httpStatus, linkStatus };
|
|
1832
|
-
}
|
|
1833
|
-
function riddleApiStrictSafetyWarnings(blocker) {
|
|
1834
|
-
const rawWarnings = Array.isArray(blocker?.warnings) ? blocker.warnings.filter((warning) => typeof warning === "string") : [];
|
|
1835
|
-
const errorText = typeof blocker?.error === "string" ? blocker.error.toLowerCase() : "";
|
|
1836
|
-
const hasSafetyError = errorText.includes("potentially unsafe operations");
|
|
1837
|
-
const hasDirectNetworkWarning = rawWarnings.some((warning) => warning.toLowerCase().includes("direct network operations"));
|
|
1838
|
-
return hasSafetyError || hasDirectNetworkWarning ? rawWarnings : [];
|
|
1839
|
-
}
|
|
1840
|
-
function collectRiddleProofProfileEnvironmentBlockedWarnings(profile, blocker) {
|
|
1841
|
-
const warnings = collectRiddleProofProfileWarnings(profile);
|
|
1842
|
-
const safetyWarnings = riddleApiStrictSafetyWarnings(blocker);
|
|
1843
|
-
if (!safetyWarnings.length) return warnings;
|
|
1844
|
-
const counts = profileStatusProbeCounts(profile);
|
|
1845
|
-
const statusProbeCount = counts.httpStatus + counts.linkStatus;
|
|
1846
|
-
if (!statusProbeCount) return warnings;
|
|
1847
|
-
const parts = [
|
|
1848
|
-
counts.httpStatus ? `${counts.httpStatus} http_status` : "",
|
|
1849
|
-
counts.linkStatus ? `${counts.linkStatus} link_status/artifact_link_status` : ""
|
|
1850
|
-
].filter(Boolean);
|
|
1851
|
-
warnings.push(
|
|
1852
|
-
`Riddle API strict script validation blocked a hosted profile runner with ${parts.join(" and ")} check(s). These checks intentionally collect endpoint/link evidence from inside the generated browser runner; hosted run-profile defaults to --strict=false, so omit --strict=true or rerun with --strict=false for trusted generated profile runs.`
|
|
1853
|
-
);
|
|
1854
|
-
return warnings;
|
|
1855
|
-
}
|
|
1856
|
-
function normalizeRouteInventoryPath(value, label) {
|
|
1857
|
-
const path = stringValue(value);
|
|
1858
|
-
if (!path) throw new Error(`${label} requires path.`);
|
|
1859
|
-
if (!path.startsWith("/")) throw new Error(`${label}.path must start with /.`);
|
|
1860
|
-
return normalizeRoutePath(path);
|
|
1861
|
-
}
|
|
1862
|
-
function normalizeRouteInventoryRoute(input, index) {
|
|
1863
|
-
if (typeof input === "string") return { path: normalizeRouteInventoryPath(input, `checks route_inventory expected_routes[${index}]`) };
|
|
1864
|
-
if (!isRecord(input)) throw new Error(`checks route_inventory expected_routes[${index}] must be a string or object.`);
|
|
1865
|
-
return {
|
|
1866
|
-
name: stringValue(input.name),
|
|
1867
|
-
path: normalizeRouteInventoryPath(input.path, `checks route_inventory expected_routes[${index}]`)
|
|
1868
|
-
};
|
|
1869
|
-
}
|
|
1870
|
-
function normalizeRouteInventoryRoutes(value, index) {
|
|
1871
|
-
if (value === void 0) return void 0;
|
|
1872
|
-
if (!Array.isArray(value) || value.length === 0) {
|
|
1873
|
-
throw new Error(`checks[${index}] route_inventory expected_routes must be a non-empty array.`);
|
|
1874
|
-
}
|
|
1875
|
-
const routes = value.map(normalizeRouteInventoryRoute);
|
|
1876
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1877
|
-
for (const route of routes) {
|
|
1878
|
-
if (seen.has(route.path)) throw new Error(`checks[${index}] route_inventory expected_routes contains duplicate path ${route.path}.`);
|
|
1879
|
-
seen.add(route.path);
|
|
1880
|
-
}
|
|
1881
|
-
return routes;
|
|
1882
|
-
}
|
|
1883
|
-
function normalizeExpectedTexts(value, index) {
|
|
1884
|
-
if (value === void 0) return void 0;
|
|
1885
|
-
if (!Array.isArray(value) || value.length === 0) {
|
|
1886
|
-
throw new Error(`checks[${index}] selector_text_order expected_texts must be a non-empty array.`);
|
|
1887
|
-
}
|
|
1888
|
-
const texts = value.map((item) => String(item).replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
1889
|
-
if (!texts.length) throw new Error(`checks[${index}] selector_text_order expected_texts must contain non-empty strings.`);
|
|
1890
|
-
return texts;
|
|
1891
|
-
}
|
|
1892
|
-
function normalizeStringList(value, label) {
|
|
1893
|
-
if (value === void 0) return void 0;
|
|
1894
|
-
if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);
|
|
1895
|
-
const values = value.map((item) => String(item).replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
1896
|
-
if (!values.length) throw new Error(`${label} must contain non-empty strings.`);
|
|
1897
|
-
return values;
|
|
1898
|
-
}
|
|
1899
|
-
function normalizeHttpStatus(value, label) {
|
|
1900
|
-
if (value === void 0) return void 0;
|
|
1901
|
-
const status = numberValue(value);
|
|
1902
|
-
if (status === void 0 || !Number.isInteger(status) || status < 100 || status > 599) {
|
|
1903
|
-
throw new Error(`${label} must be an HTTP status code.`);
|
|
1904
|
-
}
|
|
1905
|
-
return status;
|
|
1906
|
-
}
|
|
1907
|
-
function normalizeHttpStatuses(value, label) {
|
|
1908
|
-
if (value === void 0) return void 0;
|
|
1909
|
-
if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);
|
|
1910
|
-
if (!value.length) throw new Error(`${label} must not be empty.`);
|
|
1911
|
-
const statuses = value.map((item, index) => normalizeHttpStatus(item, `${label}[${index}]`));
|
|
1912
|
-
return Array.from(new Set(statuses));
|
|
1913
|
-
}
|
|
1914
|
-
function normalizePositiveInteger(value, label, max) {
|
|
1915
|
-
if (value === void 0) return void 0;
|
|
1916
|
-
const number = numberValue(value);
|
|
1917
|
-
if (number === void 0 || !Number.isInteger(number) || number < 1 || max !== void 0 && number > max) {
|
|
1918
|
-
throw new Error(`${label} must be an integer from 1 to ${max ?? "unbounded"}.`);
|
|
1919
|
-
}
|
|
1920
|
-
return number;
|
|
1921
|
-
}
|
|
1922
|
-
function validateRegexPatterns(patterns, label) {
|
|
1923
|
-
for (const pattern of patterns || []) {
|
|
1924
|
-
try {
|
|
1925
|
-
new RegExp(pattern);
|
|
1926
|
-
} catch (error) {
|
|
1927
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1928
|
-
throw new Error(`${label} contains invalid regex ${JSON.stringify(pattern)}: ${message}`);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
function normalizeHttpStatusBodyJsonAssertions(value, label) {
|
|
1933
|
-
if (value === void 0) return void 0;
|
|
1934
|
-
if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);
|
|
1935
|
-
if (!value.length) throw new Error(`${label} must not be empty.`);
|
|
1936
|
-
return value.map((item, index) => {
|
|
1937
|
-
const itemLabel = `${label}[${index}]`;
|
|
1938
|
-
if (typeof item === "string") {
|
|
1939
|
-
const path2 = stringValue(item);
|
|
1940
|
-
if (!path2) throw new Error(`${itemLabel} path must not be empty.`);
|
|
1941
|
-
return { path: path2, exists: true };
|
|
1942
|
-
}
|
|
1943
|
-
if (!isRecord(item)) throw new Error(`${itemLabel} must be an object or JSON path string.`);
|
|
1944
|
-
const path = stringFromOwn(item, "path", "json_path", "jsonPath", "key");
|
|
1945
|
-
if (!path) throw new Error(`${itemLabel}.path is required.`);
|
|
1946
|
-
const assertion = {
|
|
1947
|
-
label: stringValue(item.label),
|
|
1948
|
-
path
|
|
1949
|
-
};
|
|
1950
|
-
const exists = booleanValue(valueFromOwn(item, "exists", "present"));
|
|
1951
|
-
if (exists !== void 0) assertion.exists = exists;
|
|
1952
|
-
const type = stringValue(valueFromOwn(item, "type", "value_type", "valueType"));
|
|
1953
|
-
if (type !== void 0) {
|
|
1954
|
-
const allowedTypes = ["array", "boolean", "null", "number", "object", "string"];
|
|
1955
|
-
if (!allowedTypes.includes(type)) {
|
|
1956
|
-
throw new Error(`${itemLabel}.type must be one of ${allowedTypes.join(", ")}.`);
|
|
1957
|
-
}
|
|
1958
|
-
assertion.type = type;
|
|
1959
|
-
}
|
|
1960
|
-
const equalsValue = valueFromOwn(item, "equals", "expected", "expected_value", "expectedValue", "value");
|
|
1961
|
-
if (equalsValue !== void 0) assertion.equals = toJsonValue(equalsValue);
|
|
1962
|
-
const notEqualsValue = valueFromOwn(item, "not_equals", "notEquals", "forbidden", "forbidden_value", "forbiddenValue");
|
|
1963
|
-
if (notEqualsValue !== void 0) assertion.not_equals = toJsonValue(notEqualsValue);
|
|
1964
|
-
const containsValue = valueFromOwn(item, "contains", "includes", "contains_value", "containsValue", "include");
|
|
1965
|
-
if (containsValue !== void 0) assertion.contains = toJsonValue(containsValue);
|
|
1966
|
-
if (assertion.exists === void 0 && assertion.type === void 0 && !hasOwn(assertion, "equals") && !hasOwn(assertion, "not_equals") && !hasOwn(assertion, "contains")) {
|
|
1967
|
-
assertion.exists = true;
|
|
1968
|
-
}
|
|
1969
|
-
return assertion;
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
function isDialogCountCheckType(type) {
|
|
1973
|
-
return type === "dialog_count_equals" || type === "dialog_accept_count_equals" || type === "dialog_dismiss_count_equals";
|
|
1974
|
-
}
|
|
1975
|
-
function dialogCountFieldForCheckType(type) {
|
|
1976
|
-
if (type === "dialog_accept_count_equals") return "dialog_accept_count";
|
|
1977
|
-
if (type === "dialog_dismiss_count_equals") return "dialog_dismiss_count";
|
|
1978
|
-
return "dialog_count";
|
|
1979
|
-
}
|
|
1980
|
-
function normalizeOrderedTraceEvents(value, label) {
|
|
1981
|
-
if (value === void 0) return void 0;
|
|
1982
|
-
if (!Array.isArray(value) || !value.length) throw new Error(`${label} must be a non-empty array.`);
|
|
1983
|
-
const seenLabels = /* @__PURE__ */ new Set();
|
|
1984
|
-
return value.map((item, eventIndex) => {
|
|
1985
|
-
const eventLabel = `${label}[${eventIndex}]`;
|
|
1986
|
-
if (!isRecord(item)) throw new Error(`${eventLabel} must be an object.`);
|
|
1987
|
-
const name = stringFromOwn(item, "label", "name", "event");
|
|
1988
|
-
if (!name) throw new Error(`${eventLabel}.label is required.`);
|
|
1989
|
-
if (seenLabels.has(name)) throw new Error(`${eventLabel}.label must be unique.`);
|
|
1990
|
-
seenLabels.add(name);
|
|
1991
|
-
const predicatesInput = item.predicates ?? item.all ?? item.where;
|
|
1992
|
-
if (!Array.isArray(predicatesInput) || !predicatesInput.length) {
|
|
1993
|
-
throw new Error(`${eventLabel}.predicates must be a non-empty array.`);
|
|
1994
|
-
}
|
|
1995
|
-
const predicates = predicatesInput.map((predicateInput, predicateIndex) => {
|
|
1996
|
-
const predicateLabel = `${eventLabel}.predicates[${predicateIndex}]`;
|
|
1997
|
-
if (!isRecord(predicateInput)) throw new Error(`${predicateLabel} must be an object.`);
|
|
1998
|
-
const path = stringFromOwn(predicateInput, "path", "field", "key");
|
|
1999
|
-
if (!path) throw new Error(`${predicateLabel}.path is required.`);
|
|
2000
|
-
const op = stringFromOwn(predicateInput, "op", "operator");
|
|
2001
|
-
if (!op || !RIDDLE_PROOF_ORDERED_TRACE_OPERATORS.includes(op)) {
|
|
2002
|
-
throw new Error(`${predicateLabel}.op must be one of ${RIDDLE_PROOF_ORDERED_TRACE_OPERATORS.join(", ")}.`);
|
|
2003
|
-
}
|
|
2004
|
-
const requiresValue = !["exists", "truthy", "falsy"].includes(op);
|
|
2005
|
-
const hasValue = hasOwn(predicateInput, "value") || hasOwn(predicateInput, "expected");
|
|
2006
|
-
if (requiresValue && !hasValue) throw new Error(`${predicateLabel}.value is required for ${op}.`);
|
|
2007
|
-
const value2 = hasOwn(predicateInput, "value") ? predicateInput.value : predicateInput.expected;
|
|
2008
|
-
if (["gt", "gte", "lt", "lte", "abs_gt", "abs_gte", "abs_lt", "abs_lte"].includes(op)) {
|
|
2009
|
-
if (typeof value2 !== "number" || !Number.isFinite(value2)) {
|
|
2010
|
-
throw new Error(`${predicateLabel}.value must be a finite number for ${op}.`);
|
|
2011
|
-
}
|
|
2012
|
-
if (op.startsWith("abs_") && value2 < 0) {
|
|
2013
|
-
throw new Error(`${predicateLabel}.value must be non-negative for ${op}.`);
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
return {
|
|
2017
|
-
path,
|
|
2018
|
-
op,
|
|
2019
|
-
value: requiresValue ? toJsonValue(value2) : void 0
|
|
2020
|
-
};
|
|
2021
|
-
});
|
|
2022
|
-
return { label: name, predicates };
|
|
2023
|
-
});
|
|
2024
|
-
}
|
|
2025
|
-
function normalizeCheck(input, index) {
|
|
2026
|
-
if (!isRecord(input)) throw new Error(`checks[${index}] must be an object.`);
|
|
2027
|
-
const type = stringValue(input.type);
|
|
2028
|
-
if (!type) throw new Error(`checks[${index}].type is required.`);
|
|
2029
|
-
if (!isSupportedCheckType(type)) {
|
|
2030
|
-
throw new Error(`checks[${index}].type ${type} is not supported. Supported checks: ${RIDDLE_PROOF_PROFILE_CHECK_TYPES.join(", ")}`);
|
|
2031
|
-
}
|
|
2032
|
-
const isDialogCountCheck = isDialogCountCheckType(type);
|
|
2033
|
-
if ((type === "selector_visible" || type === "selector_absent" || type === "selector_count_at_least" || type === "selector_count_equals" || type === "selector_count_equal" || type === "selector_count_eq" || type === "selector_text_visible" || type === "selector_text_absent" || type === "observe_within" && !stringValue(input.text) && !stringValue(input.pattern)) && !stringValue(input.selector)) {
|
|
2034
|
-
throw new Error(`checks[${index}] ${type} requires selector.`);
|
|
2035
|
-
}
|
|
2036
|
-
if ((type === "frame_text_visible" || type === "frame_url_equals" || type === "frame_url_matches" || type === "frame_no_horizontal_overflow") && !stringValue(input.selector)) {
|
|
2037
|
-
throw new Error(`checks[${index}] ${type} requires selector.`);
|
|
2038
|
-
}
|
|
2039
|
-
if (type === "frame_text_visible" && !stringValue(input.text) && !stringValue(input.pattern)) {
|
|
2040
|
-
throw new Error(`checks[${index}] frame_text_visible requires text or pattern.`);
|
|
2041
|
-
}
|
|
2042
|
-
const expectedUrl = stringFromOwn(input, "expected_url", "expectedUrl", "url", "expected_value", "expectedValue", "value");
|
|
2043
|
-
if (type === "frame_url_equals" && expectedUrl === void 0) {
|
|
2044
|
-
throw new Error(`checks[${index}] frame_url_equals requires expected_url.`);
|
|
2045
|
-
}
|
|
2046
|
-
if (type === "frame_url_matches" && !stringValue(input.pattern)) {
|
|
2047
|
-
throw new Error(`checks[${index}] frame_url_matches requires pattern.`);
|
|
2048
|
-
}
|
|
2049
|
-
if ((type === "text_visible" || type === "text_absent" || type === "selector_text_visible" || type === "selector_text_absent") && !stringValue(input.text) && !stringValue(input.pattern)) {
|
|
2050
|
-
throw new Error(`checks[${index}] ${type} requires text or pattern.`);
|
|
2051
|
-
}
|
|
2052
|
-
if ((type === "url_search_param_equals" || type === "url_search_param_absent") && !stringValue(input.param) && !stringValue(input.search_param) && !stringValue(input.searchParam) && !stringValue(input.key)) {
|
|
2053
|
-
throw new Error(`checks[${index}] ${type} requires param.`);
|
|
2054
|
-
}
|
|
2055
|
-
const expectedValue = stringFromOwn(input, "expected_value", "expectedValue", "value");
|
|
2056
|
-
if (type === "url_search_param_equals" && expectedValue === void 0) {
|
|
2057
|
-
throw new Error(`checks[${index}] url_search_param_equals requires expected_value.`);
|
|
2058
|
-
}
|
|
2059
|
-
const minCount = numberValue(input.min_count) ?? numberValue(input.minCount);
|
|
2060
|
-
if (type === "selector_count_at_least" && minCount === void 0) {
|
|
2061
|
-
throw new Error(`checks[${index}] selector_count_at_least requires min_count.`);
|
|
2062
|
-
}
|
|
2063
|
-
const expectedCount = numberValue(input.expected_count) ?? numberValue(input.expectedCount) ?? numberValue(input.count);
|
|
2064
|
-
if ((type === "selector_count_equals" || type === "selector_count_equal" || type === "selector_count_eq" || isDialogCountCheck) && expectedCount === void 0) {
|
|
2065
|
-
throw new Error(`checks[${index}] ${type} requires expected_count.`);
|
|
2066
|
-
}
|
|
2067
|
-
if (isDialogCountCheck && (expectedCount === void 0 || !Number.isInteger(expectedCount) || expectedCount < 0)) {
|
|
2068
|
-
throw new Error(`checks[${index}] ${type} expected_count must be a non-negative integer.`);
|
|
2069
|
-
}
|
|
2070
|
-
const expectedTexts = normalizeExpectedTexts(input.expected_texts ?? input.expectedTexts, index);
|
|
2071
|
-
if (type === "selector_text_order") {
|
|
2072
|
-
if (!stringValue(input.selector)) throw new Error(`checks[${index}] selector_text_order requires selector.`);
|
|
2073
|
-
if (!expectedTexts?.length) throw new Error(`checks[${index}] selector_text_order requires expected_texts.`);
|
|
2074
|
-
}
|
|
2075
|
-
const setupActionLabel = stringFromOwn(input, "setup_action_label", "setupActionLabel", "source_action_label", "sourceActionLabel");
|
|
2076
|
-
const tracePath = stringFromOwn(input, "trace_path", "tracePath", "path");
|
|
2077
|
-
const orderedTraceEvents = normalizeOrderedTraceEvents(
|
|
2078
|
-
input.events ?? input.sequence ?? input.ordered_events ?? input.orderedEvents,
|
|
2079
|
-
`checks[${index}].events`
|
|
2080
|
-
);
|
|
2081
|
-
if (type === "ordered_trace") {
|
|
2082
|
-
if (!setupActionLabel) throw new Error(`checks[${index}] ordered_trace requires setup_action_label.`);
|
|
2083
|
-
if (!tracePath) throw new Error(`checks[${index}] ordered_trace requires trace_path.`);
|
|
2084
|
-
if (!orderedTraceEvents?.length) throw new Error(`checks[${index}] ordered_trace requires events.`);
|
|
2085
|
-
}
|
|
2086
|
-
const expectedRoutes = normalizeRouteInventoryRoutes(input.expected_routes ?? input.expectedRoutes, index);
|
|
2087
|
-
if (type === "route_inventory" && !expectedRoutes?.length) {
|
|
2088
|
-
throw new Error(`checks[${index}] route_inventory requires expected_routes.`);
|
|
2089
|
-
}
|
|
2090
|
-
const isHttpStatusCheck = type === "http_status";
|
|
2091
|
-
const isLinkStatusCheck = type === "link_status" || type === "artifact_link_status";
|
|
2092
|
-
const isStatusCheck = isHttpStatusCheck || isLinkStatusCheck;
|
|
2093
|
-
const requestUrl = stringFromOwn(input, "url", "endpoint_url", "endpointUrl", "endpoint", "request_url", "requestUrl", "path");
|
|
2094
|
-
if (isHttpStatusCheck && !requestUrl) {
|
|
2095
|
-
throw new Error(`checks[${index}] http_status requires url.`);
|
|
2096
|
-
}
|
|
2097
|
-
const method = stringFromOwn(input, "method", "http_method", "httpMethod")?.toUpperCase();
|
|
2098
|
-
if (isHttpStatusCheck && method && !/^[A-Z]+$/.test(method)) {
|
|
2099
|
-
throw new Error(`checks[${index}] http_status method must contain only letters.`);
|
|
2100
|
-
}
|
|
2101
|
-
const hasBodyJson = hasOwn(input, "body_json") || hasOwn(input, "bodyJson") || hasOwn(input, "json");
|
|
2102
|
-
const expectedStatus = isStatusCheck ? normalizeHttpStatus(input.expected_status ?? input.expectedStatus ?? input.status, `checks[${index}] expected_status`) : void 0;
|
|
2103
|
-
const allowedStatuses = isStatusCheck ? normalizeHttpStatuses(
|
|
2104
|
-
input.allowed_statuses ?? input.allowedStatuses ?? input.expected_statuses ?? input.expectedStatuses,
|
|
2105
|
-
`checks[${index}] allowed_statuses`
|
|
2106
|
-
) : void 0;
|
|
2107
|
-
const maxLinks = isLinkStatusCheck ? normalizePositiveInteger(input.max_links ?? input.maxLinks ?? input.limit, `checks[${index}] max_links`, 500) : void 0;
|
|
2108
|
-
const minBytes = isStatusCheck ? normalizePositiveInteger(input.min_bytes ?? input.minBytes ?? input.min_response_bytes ?? input.minResponseBytes, `checks[${index}] min_bytes`) : void 0;
|
|
2109
|
-
const expectedContentType = isStatusCheck ? stringValue(input.expected_content_type) || stringValue(input.expectedContentType) || stringValue(input.content_type) || stringValue(input.contentType) : void 0;
|
|
2110
|
-
const allowedContentTypes = isStatusCheck ? normalizeStringList(
|
|
2111
|
-
input.allowed_content_types ?? input.allowedContentTypes ?? input.expected_content_types ?? input.expectedContentTypes,
|
|
2112
|
-
`checks[${index}] allowed_content_types`
|
|
2113
|
-
) ?? (expectedContentType ? [expectedContentType] : void 0) : void 0;
|
|
2114
|
-
const bodyContains = isHttpStatusCheck ? normalizeStringList(
|
|
2115
|
-
input.body_contains ?? input.bodyContains ?? input.expected_body_contains ?? input.expectedBodyContains ?? input.response_body_contains ?? input.responseBodyContains ?? input.body_includes ?? input.bodyIncludes,
|
|
2116
|
-
`checks[${index}] body_contains`
|
|
2117
|
-
) : void 0;
|
|
2118
|
-
const bodyNotContains = isHttpStatusCheck ? normalizeStringList(
|
|
2119
|
-
input.body_not_contains ?? input.bodyNotContains ?? input.expected_body_not_contains ?? input.expectedBodyNotContains ?? input.response_body_not_contains ?? input.responseBodyNotContains ?? input.body_absent ?? input.bodyAbsent,
|
|
2120
|
-
`checks[${index}] body_not_contains`
|
|
2121
|
-
) : void 0;
|
|
2122
|
-
const bodyNotPatterns = isHttpStatusCheck ? normalizeStringList(
|
|
2123
|
-
input.body_not_patterns ?? input.bodyNotPatterns ?? input.expected_body_not_patterns ?? input.expectedBodyNotPatterns ?? input.response_body_not_patterns ?? input.responseBodyNotPatterns ?? input.body_forbidden_patterns ?? input.bodyForbiddenPatterns,
|
|
2124
|
-
`checks[${index}] body_not_patterns`
|
|
2125
|
-
) : void 0;
|
|
2126
|
-
if (bodyNotPatterns?.length) validateRegexPatterns(bodyNotPatterns, `checks[${index}] body_not_patterns`);
|
|
2127
|
-
const bodyJsonAssertions = isHttpStatusCheck ? normalizeHttpStatusBodyJsonAssertions(
|
|
2128
|
-
input.body_json_assertions ?? input.bodyJsonAssertions ?? input.json_body_assertions ?? input.jsonBodyAssertions ?? input.json_assertions ?? input.jsonAssertions ?? input.response_json_assertions ?? input.responseJsonAssertions,
|
|
2129
|
-
`checks[${index}] body_json_assertions`
|
|
2130
|
-
) : void 0;
|
|
2131
|
-
if (isLinkStatusCheck) {
|
|
2132
|
-
if (minCount !== void 0 && (!Number.isInteger(minCount) || minCount < 0)) {
|
|
2133
|
-
throw new Error(`checks[${index}] ${type} min_count must be a non-negative integer.`);
|
|
2134
|
-
}
|
|
2135
|
-
if (expectedCount !== void 0 && (!Number.isInteger(expectedCount) || expectedCount < 0)) {
|
|
2136
|
-
throw new Error(`checks[${index}] ${type} expected_count must be a non-negative integer.`);
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
return {
|
|
2140
|
-
type,
|
|
2141
|
-
label: stringValue(input.label),
|
|
2142
|
-
expected_path: stringValue(input.expected_path),
|
|
2143
|
-
param: stringValue(input.param) || stringValue(input.search_param) || stringValue(input.searchParam) || stringValue(input.key),
|
|
2144
|
-
expected_value: expectedValue,
|
|
2145
|
-
expected_url: expectedUrl,
|
|
2146
|
-
expected_routes: expectedRoutes,
|
|
2147
|
-
selector: stringValue(input.selector),
|
|
2148
|
-
url: isHttpStatusCheck ? requestUrl : void 0,
|
|
2149
|
-
method: isHttpStatusCheck ? method || "GET" : void 0,
|
|
2150
|
-
headers: isHttpStatusCheck ? stringRecord(input.headers) : void 0,
|
|
2151
|
-
body: isHttpStatusCheck ? stringValue(input.body) : void 0,
|
|
2152
|
-
body_json: isHttpStatusCheck && hasBodyJson ? toJsonValue(input.body_json ?? input.bodyJson ?? input.json) : void 0,
|
|
2153
|
-
body_contains: bodyContains,
|
|
2154
|
-
body_not_contains: bodyNotContains,
|
|
2155
|
-
body_not_patterns: bodyNotPatterns,
|
|
2156
|
-
body_json_assertions: bodyJsonAssertions,
|
|
2157
|
-
expected_texts: expectedTexts,
|
|
2158
|
-
setup_action_label: type === "ordered_trace" ? setupActionLabel : void 0,
|
|
2159
|
-
trace_path: type === "ordered_trace" ? tracePath : void 0,
|
|
2160
|
-
events: type === "ordered_trace" ? orderedTraceEvents : void 0,
|
|
2161
|
-
link_selector: stringValue(input.link_selector) || stringValue(input.linkSelector),
|
|
2162
|
-
source_selector: stringValue(input.source_selector) || stringValue(input.sourceSelector),
|
|
2163
|
-
route_path_prefix: stringValue(input.route_path_prefix) || stringValue(input.routePathPrefix),
|
|
2164
|
-
route_ready_selector: stringValue(input.route_ready_selector) || stringValue(input.routeReadySelector),
|
|
2165
|
-
route_ready_text: stringValue(input.route_ready_text) || stringValue(input.routeReadyText),
|
|
2166
|
-
route_ready_pattern: stringValue(input.route_ready_pattern) || stringValue(input.routeReadyPattern),
|
|
2167
|
-
route_ready_flags: stringValue(input.route_ready_flags) || stringValue(input.routeReadyFlags),
|
|
2168
|
-
text: stringValue(input.text),
|
|
2169
|
-
pattern: stringValue(input.pattern),
|
|
2170
|
-
flags: stringValue(input.flags),
|
|
2171
|
-
viewports: normalizeStringList(input.viewports ?? input.viewport_names ?? input.viewportNames, `checks[${index}] viewports`),
|
|
2172
|
-
allowed_console_texts: normalizeStringList(input.allowed_console_texts ?? input.allowedConsoleTexts ?? input.allow_console_texts ?? input.allowConsoleTexts, `checks[${index}] allowed_console_texts`),
|
|
2173
|
-
allowed_console_patterns: normalizeStringList(input.allowed_console_patterns ?? input.allowedConsolePatterns ?? input.allow_console_patterns ?? input.allowConsolePatterns, `checks[${index}] allowed_console_patterns`),
|
|
2174
|
-
allowed_page_error_texts: normalizeStringList(input.allowed_page_error_texts ?? input.allowedPageErrorTexts ?? input.allow_page_error_texts ?? input.allowPageErrorTexts, `checks[${index}] allowed_page_error_texts`),
|
|
2175
|
-
allowed_page_error_patterns: normalizeStringList(input.allowed_page_error_patterns ?? input.allowedPageErrorPatterns ?? input.allow_page_error_patterns ?? input.allowPageErrorPatterns, `checks[${index}] allowed_page_error_patterns`),
|
|
2176
|
-
min_count: minCount,
|
|
2177
|
-
expected_count: expectedCount,
|
|
2178
|
-
expected_status: expectedStatus,
|
|
2179
|
-
allowed_statuses: allowedStatuses,
|
|
2180
|
-
max_links: maxLinks,
|
|
2181
|
-
same_origin_only: isLinkStatusCheck ? input.same_origin_only === true || input.sameOriginOnly === true : void 0,
|
|
2182
|
-
dedupe: isLinkStatusCheck ? input.dedupe === false ? false : true : void 0,
|
|
2183
|
-
require_nonzero_bytes: isStatusCheck ? input.require_nonzero_bytes === true || input.requireNonzeroBytes === true : void 0,
|
|
2184
|
-
min_bytes: minBytes,
|
|
2185
|
-
allowed_content_types: allowedContentTypes,
|
|
2186
|
-
allow_get_fallback: isLinkStatusCheck ? input.allow_get_fallback === false || input.allowGetFallback === false ? false : true : void 0,
|
|
2187
|
-
max_overflow_px: numberValue(input.max_overflow_px),
|
|
2188
|
-
timeout_ms: numberValue(input.timeout_ms) ?? numberValue(input.timeoutMs) ?? numberValue(input.within_ms) ?? numberValue(input.withinMs),
|
|
2189
|
-
run_direct_routes: input.run_direct_routes === false || input.runDirectRoutes === false ? false : true,
|
|
2190
|
-
run_clickthroughs: input.run_clickthroughs === false || input.runClickthroughs === false ? false : true,
|
|
2191
|
-
run_all_viewports: input.run_all_viewports === true || input.runAllViewports === true,
|
|
2192
|
-
require_unique_routes: input.require_unique_routes === false || input.requireUniqueRoutes === false ? false : true,
|
|
2193
|
-
allow_unexpected_routes: input.allow_unexpected_routes === true || input.allowUnexpectedRoutes === true,
|
|
2194
|
-
save_route_screenshots: input.save_route_screenshots === true || input.saveRouteScreenshots === true
|
|
2195
|
-
};
|
|
2196
|
-
}
|
|
2197
|
-
function normalizeFailurePolicy(input) {
|
|
2198
|
-
const defaults = {
|
|
2199
|
-
product_regression: "fail",
|
|
2200
|
-
proof_insufficient: "fail",
|
|
2201
|
-
environment_blocked: "neutral",
|
|
2202
|
-
configuration_error: "fail",
|
|
2203
|
-
needs_human_review: "fail"
|
|
2204
|
-
};
|
|
2205
|
-
if (!isRecord(input)) return defaults;
|
|
2206
|
-
const next = { ...defaults };
|
|
2207
|
-
for (const [key, value] of Object.entries(input)) {
|
|
2208
|
-
if (!RIDDLE_PROOF_PROFILE_STATUSES.includes(key)) continue;
|
|
2209
|
-
if (value === "fail" || value === "neutral" || value === "review") {
|
|
2210
|
-
next[key] = value;
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
return next;
|
|
2214
|
-
}
|
|
2215
|
-
function normalizeRiddleProofProfile(input, options = {}) {
|
|
2216
|
-
if (!isRecord(input)) throw new Error("profile must be a JSON object.");
|
|
2217
|
-
const version = stringValue(input.version) || RIDDLE_PROOF_PROFILE_VERSION;
|
|
2218
|
-
if (version !== RIDDLE_PROOF_PROFILE_VERSION) {
|
|
2219
|
-
throw new Error(`Unsupported profile version ${version}. Expected ${RIDDLE_PROOF_PROFILE_VERSION}.`);
|
|
2220
|
-
}
|
|
2221
|
-
const targetInput = isRecord(input.target) ? input.target : {};
|
|
2222
|
-
const checks = Array.isArray(input.checks) ? input.checks.map(normalizeCheck) : [];
|
|
2223
|
-
if (!checks.length) throw new Error("profile.checks must contain at least one check.");
|
|
2224
|
-
const targetUrl = stringValue(options.url) || stringValue(targetInput.url);
|
|
2225
|
-
const route = stringValue(options.route) || stringValue(targetInput.route);
|
|
2226
|
-
if (!targetUrl && !route) throw new Error("profile.target requires url or route, or pass --url.");
|
|
2227
|
-
const setupActions = normalizeSetupActions(targetInput.setup_actions ?? targetInput.setupActions);
|
|
2228
|
-
for (const [index, check] of checks.entries()) {
|
|
2229
|
-
if (check.type !== "ordered_trace") continue;
|
|
2230
|
-
const matches = (setupActions || []).filter((action) => action.label === check.setup_action_label);
|
|
2231
|
-
if (matches.length !== 1) {
|
|
2232
|
-
throw new Error(`checks[${index}] ordered_trace setup_action_label must match exactly one target.setup_actions label.`);
|
|
2233
|
-
}
|
|
2234
|
-
if (!["window_eval", "window_call", "window_call_until"].includes(matches[0].type)) {
|
|
2235
|
-
throw new Error(`checks[${index}] ordered_trace source action must capture a window_eval, window_call, or window_call_until return.`);
|
|
2236
|
-
}
|
|
2237
|
-
if (matches[0].capture_return === false) {
|
|
2238
|
-
throw new Error(`checks[${index}] ordered_trace source action must not set capture_return to false.`);
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
return {
|
|
2242
|
-
version: RIDDLE_PROOF_PROFILE_VERSION,
|
|
2243
|
-
name: normalizeName(input.name, "riddle-proof-profile"),
|
|
2244
|
-
target: {
|
|
2245
|
-
url: targetUrl,
|
|
2246
|
-
route,
|
|
2247
|
-
viewports: options.viewports?.length ? options.viewports : normalizeViewports(targetInput.viewports),
|
|
2248
|
-
auth: stringValue(targetInput.auth) || "none",
|
|
2249
|
-
timeout_sec: timeoutSecValue(targetInput.timeout_sec) ?? timeoutSecValue(targetInput.timeoutSec) ?? timeoutSecValue(targetInput.riddle_timeout_sec) ?? timeoutSecValue(targetInput.riddleTimeoutSec),
|
|
2250
|
-
wait_for_selector: stringValue(targetInput.wait_for_selector) || stringValue(targetInput.waitForSelector),
|
|
2251
|
-
wait_ms: numberValue(targetInput.wait_ms) ?? numberValue(targetInput.waitMs),
|
|
2252
|
-
screenshot_full_page: normalizeTargetScreenshotFullPage(targetInput),
|
|
2253
|
-
setup_actions: setupActions,
|
|
2254
|
-
network_mocks: normalizeNetworkMocks(targetInput.network_mocks ?? targetInput.networkMocks)
|
|
2255
|
-
},
|
|
2256
|
-
checks,
|
|
2257
|
-
artifacts: Array.isArray(input.artifacts) ? input.artifacts.map((item) => String(item)).filter(Boolean) : ["screenshot", "console", "dom_summary", "proof_json"],
|
|
2258
|
-
baseline_policy: stringValue(input.baseline_policy) || stringValue(input.baselinePolicy) || "invariant_only",
|
|
2259
|
-
failure_policy: normalizeFailurePolicy(input.failure_policy || input.failurePolicy),
|
|
2260
|
-
metadata: jsonRecord(input.metadata)
|
|
2261
|
-
};
|
|
2262
|
-
}
|
|
2263
|
-
function resolveRiddleProofProfileTargetUrl(profile) {
|
|
2264
|
-
const route = profile.target.route || "";
|
|
2265
|
-
const targetUrl = profile.target.url || "";
|
|
2266
|
-
if (targetUrl && route) return resolveRiddleProofProfileRouteUrl(targetUrl, route);
|
|
2267
|
-
if (/^https?:\/\//i.test(route)) return route;
|
|
2268
|
-
if (targetUrl) return targetUrl;
|
|
2269
|
-
throw new Error("profile target URL could not be resolved.");
|
|
2270
|
-
}
|
|
2271
|
-
function resolveRiddleProofProfileTimeoutSec(profile, requestedTimeoutSec) {
|
|
2272
|
-
return timeoutSecValue(requestedTimeoutSec) ?? timeoutSecValue(profile.target.timeout_sec);
|
|
2273
|
-
}
|
|
2274
|
-
function routeForViewport(viewport, targetUrl) {
|
|
2275
|
-
if (viewport?.route) {
|
|
2276
|
-
return {
|
|
2277
|
-
...viewport.route,
|
|
2278
|
-
matched: viewport.route.matched || routePathMatches(viewport.route.observed, viewport.route.expected_path, targetUrl)
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
return {
|
|
2282
|
-
requested: "",
|
|
2283
|
-
observed: "",
|
|
2284
|
-
matched: false,
|
|
2285
|
-
error: "missing viewport evidence"
|
|
2286
|
-
};
|
|
2287
|
-
}
|
|
2288
|
-
function checkLabel(check) {
|
|
2289
|
-
return check.label || check.type;
|
|
2290
|
-
}
|
|
2291
|
-
function selectorKey(check) {
|
|
2292
|
-
return check.selector || "";
|
|
2293
|
-
}
|
|
2294
|
-
function linkStatusSelector(check) {
|
|
2295
|
-
return check.selector || check.link_selector || "a[href]";
|
|
2296
|
-
}
|
|
2297
|
-
function httpStatusRequestUrl(check, baseUrl) {
|
|
2298
|
-
const rawUrl = check.url || "";
|
|
2299
|
-
if (!rawUrl) return "";
|
|
2300
|
-
try {
|
|
2301
|
-
if (baseUrl && rawUrl.startsWith("/") && !rawUrl.startsWith("//")) {
|
|
2302
|
-
const base = new URL(baseUrl);
|
|
2303
|
-
const mountPrefix = previewMountPrefix(base.pathname);
|
|
2304
|
-
if (mountPrefix) {
|
|
2305
|
-
const requested = new URL(rawUrl, base.origin);
|
|
2306
|
-
base.pathname = joinMountedRoutePath(mountPrefix, requested.pathname);
|
|
2307
|
-
base.search = requested.search;
|
|
2308
|
-
base.hash = requested.hash;
|
|
2309
|
-
return base.href;
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
return baseUrl ? new URL(rawUrl, baseUrl).href : new URL(rawUrl).href;
|
|
2313
|
-
} catch {
|
|
2314
|
-
return rawUrl;
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
function httpStatusMethod(check) {
|
|
2318
|
-
return (check.method || "GET").toUpperCase();
|
|
2319
|
-
}
|
|
2320
|
-
function httpStatusKey(check, baseUrl) {
|
|
2321
|
-
return `${httpStatusMethod(check)} ${httpStatusRequestUrl(check, baseUrl)}`;
|
|
2322
|
-
}
|
|
2323
|
-
function httpStatusAllowedStatuses(check) {
|
|
2324
|
-
if (check.allowed_statuses?.length) return check.allowed_statuses;
|
|
2325
|
-
if (check.expected_status !== void 0) return [check.expected_status];
|
|
2326
|
-
return void 0;
|
|
2327
|
-
}
|
|
2328
|
-
function linkStatusAllowedStatuses(check) {
|
|
2329
|
-
return httpStatusAllowedStatuses(check);
|
|
2330
|
-
}
|
|
2331
|
-
function httpStatusIsAllowed(status, check) {
|
|
2332
|
-
if (status === void 0) return false;
|
|
2333
|
-
const allowed = httpStatusAllowedStatuses(check);
|
|
2334
|
-
return allowed?.length ? allowed.includes(status) : status >= 200 && status < 400;
|
|
2335
|
-
}
|
|
2336
|
-
function linkStatusObservedBytes(result) {
|
|
2337
|
-
const bytes = numberValue(result.bytes);
|
|
2338
|
-
const contentLength = numberValue(result.content_length);
|
|
2339
|
-
return Math.max(bytes ?? 0, contentLength ?? 0) || void 0;
|
|
2340
|
-
}
|
|
2341
|
-
function normalizeLinkStatusContentType(value) {
|
|
2342
|
-
const normalized = value?.split(";")[0]?.trim().toLowerCase();
|
|
2343
|
-
return normalized || void 0;
|
|
2344
|
-
}
|
|
2345
|
-
function linkStatusContentTypesMatch(actual, expected) {
|
|
2346
|
-
if (!actual || !expected) return false;
|
|
2347
|
-
if (expected.endsWith("/*")) return actual.startsWith(expected.slice(0, -1));
|
|
2348
|
-
if (actual === expected) return true;
|
|
2349
|
-
const yamlTypes = /* @__PURE__ */ new Set(["application/yaml", "application/x-yaml", "text/yaml", "text/x-yaml"]);
|
|
2350
|
-
return yamlTypes.has(actual) && yamlTypes.has(expected);
|
|
2351
|
-
}
|
|
2352
|
-
function linkStatusContentTypeOk(result, check) {
|
|
2353
|
-
const expected = check.allowed_content_types;
|
|
2354
|
-
if (!expected?.length) return true;
|
|
2355
|
-
const actual = normalizeLinkStatusContentType(stringValue(result.content_type));
|
|
2356
|
-
if (!actual) return false;
|
|
2357
|
-
return expected.some((contentType) => {
|
|
2358
|
-
const normalized = normalizeLinkStatusContentType(contentType);
|
|
2359
|
-
if (!normalized) return false;
|
|
2360
|
-
return linkStatusContentTypesMatch(actual, normalized);
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
function httpStatusBodyContainsFailures(result, check) {
|
|
2364
|
-
const expected = check.body_contains?.filter(Boolean) ?? [];
|
|
2365
|
-
if (!expected.length) return [];
|
|
2366
|
-
const observed = isRecord(result.body_contains) ? result.body_contains : {};
|
|
2367
|
-
return expected.filter((text) => observed[text] !== true);
|
|
2368
|
-
}
|
|
2369
|
-
function httpStatusBodyNotContainsFailures(result, check) {
|
|
2370
|
-
const forbidden = check.body_not_contains?.filter(Boolean) ?? [];
|
|
2371
|
-
if (!forbidden.length) return [];
|
|
2372
|
-
const observed = isRecord(result.body_not_contains) ? result.body_not_contains : {};
|
|
2373
|
-
return forbidden.filter((text) => observed[text] !== false);
|
|
2374
|
-
}
|
|
2375
|
-
function httpStatusBodyNotPatternFailures(result, check) {
|
|
2376
|
-
const forbidden = check.body_not_patterns?.filter(Boolean) ?? [];
|
|
2377
|
-
if (!forbidden.length) return [];
|
|
2378
|
-
const observed = isRecord(result.body_not_patterns) ? result.body_not_patterns : {};
|
|
2379
|
-
return forbidden.filter((pattern) => observed[pattern] !== false);
|
|
2380
|
-
}
|
|
2381
|
-
function httpStatusBodyJsonAssertionFailures(result, check) {
|
|
2382
|
-
const expected = check.body_json_assertions?.filter((assertion) => assertion.path) ?? [];
|
|
2383
|
-
if (!expected.length) return [];
|
|
2384
|
-
if (!Array.isArray(result.body_json_assertions)) {
|
|
2385
|
-
return expected.map((assertion) => ({
|
|
2386
|
-
label: assertion.label || assertion.path,
|
|
2387
|
-
path: assertion.path,
|
|
2388
|
-
ok: false,
|
|
2389
|
-
exists: false,
|
|
2390
|
-
observed_type: "missing",
|
|
2391
|
-
errors: ["body_json_assertions evidence missing"]
|
|
2392
|
-
}));
|
|
2393
|
-
}
|
|
2394
|
-
return result.body_json_assertions.filter((assertion) => isRecord(assertion) && assertion.ok !== true).map((assertion) => ({
|
|
2395
|
-
label: stringValue(assertion.label) || stringValue(assertion.path) || "json assertion",
|
|
2396
|
-
path: stringValue(assertion.path) || "",
|
|
2397
|
-
ok: false,
|
|
2398
|
-
exists: assertion.exists === true,
|
|
2399
|
-
observed: hasOwn(assertion, "observed") ? toJsonValue(assertion.observed) : void 0,
|
|
2400
|
-
observed_sample: hasOwn(assertion, "observed_sample") ? toJsonValue(assertion.observed_sample) : void 0,
|
|
2401
|
-
observed_length: numberValue(assertion.observed_length),
|
|
2402
|
-
observed_key_count: numberValue(assertion.observed_key_count),
|
|
2403
|
-
observed_omitted_count: numberValue(assertion.observed_omitted_count),
|
|
2404
|
-
observed_type: stringValue(assertion.observed_type) || "missing",
|
|
2405
|
-
expected_exists: booleanValue(assertion.expected_exists),
|
|
2406
|
-
equals: hasOwn(assertion, "equals") ? toJsonValue(assertion.equals) : void 0,
|
|
2407
|
-
not_equals: hasOwn(assertion, "not_equals") ? toJsonValue(assertion.not_equals) : void 0,
|
|
2408
|
-
contains: hasOwn(assertion, "contains") ? toJsonValue(assertion.contains) : void 0,
|
|
2409
|
-
type: stringValue(assertion.type),
|
|
2410
|
-
errors: Array.isArray(assertion.errors) ? assertion.errors.map(String) : void 0
|
|
2411
|
-
}));
|
|
2412
|
-
}
|
|
2413
|
-
function linkStatusResultOk(result, check) {
|
|
2414
|
-
const status = numberValue(result.status);
|
|
2415
|
-
if (!httpStatusIsAllowed(status, check)) return false;
|
|
2416
|
-
if (stringValue(result.error)) return false;
|
|
2417
|
-
if (result.ok === false) return false;
|
|
2418
|
-
if (!linkStatusContentTypeOk(result, check)) return false;
|
|
2419
|
-
if (check.require_nonzero_bytes) {
|
|
2420
|
-
const observedBytes = linkStatusObservedBytes(result);
|
|
2421
|
-
if (observedBytes === void 0 || observedBytes <= 0) return false;
|
|
2422
|
-
}
|
|
2423
|
-
if (check.min_bytes !== void 0) {
|
|
2424
|
-
const observedBytes = linkStatusObservedBytes(result);
|
|
2425
|
-
if (observedBytes === void 0 || observedBytes < check.min_bytes) return false;
|
|
2426
|
-
}
|
|
2427
|
-
if (httpStatusBodyContainsFailures(result, check).length) return false;
|
|
2428
|
-
if (httpStatusBodyNotContainsFailures(result, check).length) return false;
|
|
2429
|
-
if (httpStatusBodyNotPatternFailures(result, check).length) return false;
|
|
2430
|
-
if (httpStatusBodyJsonAssertionFailures(result, check).length) return false;
|
|
2431
|
-
return true;
|
|
2432
|
-
}
|
|
2433
|
-
function responseHeader(response, name) {
|
|
2434
|
-
const getter = response.headers?.get;
|
|
2435
|
-
if (typeof getter !== "function") return null;
|
|
2436
|
-
return getter.call(response.headers, name);
|
|
2437
|
-
}
|
|
2438
|
-
function responseContentLength(response) {
|
|
2439
|
-
const value = responseHeader(response, "content-length");
|
|
2440
|
-
return value && /^\d+$/.test(value) ? Number(value) : null;
|
|
2441
|
-
}
|
|
2442
|
-
async function responseBodyText(response) {
|
|
2443
|
-
if (typeof response.arrayBuffer === "function") {
|
|
2444
|
-
const buffer = await response.arrayBuffer();
|
|
2445
|
-
return {
|
|
2446
|
-
text: new TextDecoder().decode(buffer),
|
|
2447
|
-
bytes: buffer.byteLength
|
|
2448
|
-
};
|
|
2449
|
-
}
|
|
2450
|
-
if (typeof response.text === "function") {
|
|
2451
|
-
const text = await response.text();
|
|
2452
|
-
return {
|
|
2453
|
-
text,
|
|
2454
|
-
bytes: new TextEncoder().encode(text).byteLength
|
|
2455
|
-
};
|
|
2456
|
-
}
|
|
2457
|
-
return { text: "", bytes: null };
|
|
2458
|
-
}
|
|
2459
|
-
function httpStatusRequestBody(check) {
|
|
2460
|
-
const headers = isRecord(check.headers) ? Object.fromEntries(Object.entries(check.headers).map(([key, value]) => [key, String(value)]).filter(([key]) => key.trim())) : {};
|
|
2461
|
-
if (check.body_json !== void 0) {
|
|
2462
|
-
if (!Object.keys(headers).some((key) => key.toLowerCase() === "content-type")) {
|
|
2463
|
-
headers["content-type"] = "application/json";
|
|
2464
|
-
}
|
|
2465
|
-
return { headers, body: JSON.stringify(check.body_json) };
|
|
2466
|
-
}
|
|
2467
|
-
if (typeof check.body === "string") {
|
|
2468
|
-
return { headers, body: check.body };
|
|
2469
|
-
}
|
|
2470
|
-
return { headers };
|
|
2471
|
-
}
|
|
2472
|
-
async function preflightHttpStatusCheck(check, index, targetUrl, fetchImpl) {
|
|
2473
|
-
const url = httpStatusRequestUrl(check, targetUrl);
|
|
2474
|
-
const method = httpStatusMethod(check);
|
|
2475
|
-
const request = httpStatusRequestBody(check);
|
|
2476
|
-
const init = {
|
|
2477
|
-
method,
|
|
2478
|
-
redirect: "follow",
|
|
2479
|
-
cache: "no-store",
|
|
2480
|
-
headers: request.headers
|
|
2481
|
-
};
|
|
2482
|
-
if (request.body !== void 0 && method !== "GET" && method !== "HEAD") {
|
|
2483
|
-
init.body = request.body;
|
|
2484
|
-
}
|
|
2485
|
-
const result = {
|
|
2486
|
-
status: null,
|
|
2487
|
-
content_type: null,
|
|
2488
|
-
content_length: null,
|
|
2489
|
-
bytes: null
|
|
2490
|
-
};
|
|
2491
|
-
let error = null;
|
|
2492
|
-
let statusText = "";
|
|
2493
|
-
try {
|
|
2494
|
-
const response = await fetchImpl(url, init);
|
|
2495
|
-
result.status = typeof response.status === "number" && Number.isFinite(response.status) ? response.status : null;
|
|
2496
|
-
statusText = typeof response.statusText === "string" ? response.statusText : "";
|
|
2497
|
-
result.content_type = responseHeader(response, "content-type");
|
|
2498
|
-
result.content_length = responseContentLength(response);
|
|
2499
|
-
const shouldReadBody = check.require_nonzero_bytes === true || typeof check.min_bytes === "number" || Boolean(check.body_contains?.length) || Boolean(check.body_not_contains?.length) || Boolean(check.body_not_patterns?.length) || Boolean(check.body_json_assertions?.length);
|
|
2500
|
-
if (shouldReadBody && method !== "HEAD") {
|
|
2501
|
-
const body = await responseBodyText(response);
|
|
2502
|
-
result.bytes = body.bytes;
|
|
2503
|
-
if (check.body_contains?.length) {
|
|
2504
|
-
result.body_contains = Object.fromEntries(check.body_contains.filter(Boolean).map((snippet) => [snippet, body.text.includes(snippet)]));
|
|
2505
|
-
}
|
|
2506
|
-
if (check.body_not_contains?.length) {
|
|
2507
|
-
result.body_not_contains = Object.fromEntries(check.body_not_contains.filter(Boolean).map((snippet) => [snippet, body.text.includes(snippet)]));
|
|
2508
|
-
}
|
|
2509
|
-
if (check.body_not_patterns?.length) {
|
|
2510
|
-
result.body_not_patterns = Object.fromEntries(check.body_not_patterns.filter(Boolean).map((pattern) => [pattern, new RegExp(pattern).test(body.text)]));
|
|
2511
|
-
}
|
|
2512
|
-
if (check.body_json_assertions?.length) {
|
|
2513
|
-
result.body_json_assertions = evaluateHttpStatusBodyJsonAssertions(body.text, check.body_json_assertions);
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
} catch (caught) {
|
|
2517
|
-
error = String(caught instanceof Error ? caught.message : caught).slice(0, 500);
|
|
2518
|
-
result.error = error;
|
|
2519
|
-
}
|
|
2520
|
-
const bodyContainsMissing = httpStatusBodyContainsFailures(result, check);
|
|
2521
|
-
const bodyNotContainsFound = httpStatusBodyNotContainsFailures(result, check);
|
|
2522
|
-
const bodyNotPatternsFound = httpStatusBodyNotPatternFailures(result, check);
|
|
2523
|
-
const bodyJsonAssertionsFailed = httpStatusBodyJsonAssertionFailures(result, check);
|
|
2524
|
-
const ok = !error && linkStatusResultOk(result, check);
|
|
2525
|
-
return {
|
|
2526
|
-
index,
|
|
2527
|
-
label: checkLabel(check) || `checks[${index}]`,
|
|
2528
|
-
url,
|
|
2529
|
-
method,
|
|
2530
|
-
ok,
|
|
2531
|
-
status: numberValue(result.status) ?? null,
|
|
2532
|
-
status_text: statusText,
|
|
2533
|
-
error,
|
|
2534
|
-
content_type: stringValue(result.content_type) ?? null,
|
|
2535
|
-
content_length: numberValue(result.content_length) ?? null,
|
|
2536
|
-
bytes: numberValue(result.bytes) ?? null,
|
|
2537
|
-
body_contains: isRecord(result.body_contains) ? Object.fromEntries(Object.entries(result.body_contains).map(([key, value]) => [key, value === true])) : null,
|
|
2538
|
-
body_contains_missing: bodyContainsMissing,
|
|
2539
|
-
body_not_contains: isRecord(result.body_not_contains) ? Object.fromEntries(Object.entries(result.body_not_contains).map(([key, value]) => [key, value === true])) : null,
|
|
2540
|
-
body_not_contains_found: bodyNotContainsFound,
|
|
2541
|
-
body_not_patterns: isRecord(result.body_not_patterns) ? Object.fromEntries(Object.entries(result.body_not_patterns).map(([key, value]) => [key, value === true])) : null,
|
|
2542
|
-
body_not_patterns_found: bodyNotPatternsFound,
|
|
2543
|
-
body_json_assertions: Array.isArray(result.body_json_assertions) ? result.body_json_assertions : null,
|
|
2544
|
-
body_json_assertions_failed: bodyJsonAssertionsFailed
|
|
2545
|
-
};
|
|
2546
|
-
}
|
|
2547
|
-
async function preflightRiddleProofProfileHttpStatusChecks(profile, options = {}) {
|
|
2548
|
-
const targetUrl = options.target_url || resolveRiddleProofProfileTargetUrl(profile);
|
|
2549
|
-
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
2550
|
-
if (typeof fetchImpl !== "function") {
|
|
2551
|
-
throw new Error("profile http_status preflight requires fetch support or options.fetchImpl.");
|
|
2552
|
-
}
|
|
2553
|
-
const httpStatusChecks = profile.checks.map((check, index) => ({ check, index })).filter((item) => item.check.type === "http_status");
|
|
2554
|
-
const checks = await Promise.all(httpStatusChecks.map((item) => preflightHttpStatusCheck(item.check, item.index, targetUrl, fetchImpl)));
|
|
2555
|
-
const failed = checks.filter((check) => !check.ok).length;
|
|
2556
|
-
return {
|
|
2557
|
-
version: "riddle-proof.profile-http-status-preflight.v1",
|
|
2558
|
-
ok: failed === 0,
|
|
2559
|
-
profile_name: profile.name,
|
|
2560
|
-
target_url: targetUrl,
|
|
2561
|
-
checked: checks.length,
|
|
2562
|
-
failed,
|
|
2563
|
-
checks,
|
|
2564
|
-
summary: failed === 0 ? `${profile.name} http_status preflight passed ${checks.length} check(s).` : `${profile.name} http_status preflight failed ${failed} of ${checks.length} check(s).`
|
|
2565
|
-
};
|
|
2566
|
-
}
|
|
2567
|
-
function httpStatusEvidenceForCheck(viewport, check) {
|
|
2568
|
-
const evidence = viewport.http_statuses?.[httpStatusKey(check, viewport.url)];
|
|
2569
|
-
return isRecord(evidence) ? evidence : void 0;
|
|
2570
|
-
}
|
|
2571
|
-
function summarizeHttpStatusEvidence(viewport, check) {
|
|
2572
|
-
const key = httpStatusKey(check, viewport.url);
|
|
2573
|
-
const statusEvidence = httpStatusEvidenceForCheck(viewport, check);
|
|
2574
|
-
if (!statusEvidence) {
|
|
2575
|
-
return {
|
|
2576
|
-
viewport: viewport.name,
|
|
2577
|
-
key,
|
|
2578
|
-
url: httpStatusRequestUrl(check, viewport.url),
|
|
2579
|
-
method: httpStatusMethod(check),
|
|
2580
|
-
ok: false,
|
|
2581
|
-
status: null,
|
|
2582
|
-
failures: [{ code: "http_status_evidence_missing" }]
|
|
2583
|
-
};
|
|
2584
|
-
}
|
|
2585
|
-
const failures = [];
|
|
2586
|
-
const bodyContainsMissing = httpStatusBodyContainsFailures(statusEvidence, check);
|
|
2587
|
-
const bodyNotContainsFound = httpStatusBodyNotContainsFailures(statusEvidence, check);
|
|
2588
|
-
const bodyNotPatternsFound = httpStatusBodyNotPatternFailures(statusEvidence, check);
|
|
2589
|
-
const bodyJsonAssertionsFailed = httpStatusBodyJsonAssertionFailures(statusEvidence, check);
|
|
2590
|
-
if (!linkStatusResultOk(statusEvidence, check)) {
|
|
2591
|
-
failures.push({
|
|
2592
|
-
code: "http_status_failed",
|
|
2593
|
-
url: stringValue(statusEvidence.url) ?? httpStatusRequestUrl(check, viewport.url),
|
|
2594
|
-
status: numberValue(statusEvidence.status) ?? null,
|
|
2595
|
-
method: stringValue(statusEvidence.method) ?? httpStatusMethod(check),
|
|
2596
|
-
error: stringValue(statusEvidence.error) ?? null,
|
|
2597
|
-
content_type: stringValue(statusEvidence.content_type) ?? null,
|
|
2598
|
-
bytes: linkStatusObservedBytes(statusEvidence) ?? null,
|
|
2599
|
-
allowed_statuses: httpStatusAllowedStatuses(check) ?? ["2xx", "3xx"],
|
|
2600
|
-
min_bytes: check.min_bytes ?? null,
|
|
2601
|
-
allowed_content_types: check.allowed_content_types ?? null,
|
|
2602
|
-
body_contains: check.body_contains ?? null,
|
|
2603
|
-
body_contains_missing: bodyContainsMissing,
|
|
2604
|
-
body_not_contains: check.body_not_contains ?? null,
|
|
2605
|
-
body_not_contains_found: bodyNotContainsFound,
|
|
2606
|
-
body_not_patterns: check.body_not_patterns ?? null,
|
|
2607
|
-
body_not_patterns_found: bodyNotPatternsFound,
|
|
2608
|
-
body_json_assertions: check.body_json_assertions ?? null,
|
|
2609
|
-
body_json_assertions_failed: bodyJsonAssertionsFailed.map((assertion) => toJsonValue(assertion)),
|
|
2610
|
-
body_sample: stringValue(statusEvidence.body_sample) ?? null
|
|
2611
|
-
});
|
|
2612
|
-
}
|
|
2613
|
-
return {
|
|
2614
|
-
viewport: viewport.name,
|
|
2615
|
-
key,
|
|
2616
|
-
url: stringValue(statusEvidence.url) ?? httpStatusRequestUrl(check, viewport.url),
|
|
2617
|
-
method: stringValue(statusEvidence.method) ?? httpStatusMethod(check),
|
|
2618
|
-
status: numberValue(statusEvidence.status) ?? null,
|
|
2619
|
-
status_text: stringValue(statusEvidence.status_text) ?? null,
|
|
2620
|
-
ok: failures.length === 0,
|
|
2621
|
-
error: stringValue(statusEvidence.error) ?? null,
|
|
2622
|
-
content_type: stringValue(statusEvidence.content_type) ?? null,
|
|
2623
|
-
content_length: numberValue(statusEvidence.content_length) ?? null,
|
|
2624
|
-
bytes: linkStatusObservedBytes(statusEvidence) ?? null,
|
|
2625
|
-
body_contains: isRecord(statusEvidence.body_contains) ? toJsonValue(statusEvidence.body_contains) : null,
|
|
2626
|
-
body_contains_missing: bodyContainsMissing,
|
|
2627
|
-
body_not_contains: isRecord(statusEvidence.body_not_contains) ? toJsonValue(statusEvidence.body_not_contains) : null,
|
|
2628
|
-
body_not_contains_found: bodyNotContainsFound,
|
|
2629
|
-
body_not_patterns: isRecord(statusEvidence.body_not_patterns) ? toJsonValue(statusEvidence.body_not_patterns) : null,
|
|
2630
|
-
body_not_patterns_found: bodyNotPatternsFound,
|
|
2631
|
-
body_json_assertions: Array.isArray(statusEvidence.body_json_assertions) ? toJsonValue(statusEvidence.body_json_assertions) : null,
|
|
2632
|
-
body_json_assertions_failed: bodyJsonAssertionsFailed.map((assertion) => toJsonValue(assertion)),
|
|
2633
|
-
body_sample: stringValue(statusEvidence.body_sample) ?? null,
|
|
2634
|
-
failures
|
|
2635
|
-
};
|
|
2636
|
-
}
|
|
2637
|
-
function linkStatusEvidenceForCheck(viewport, check) {
|
|
2638
|
-
const evidence = viewport.link_statuses?.[linkStatusSelector(check)];
|
|
2639
|
-
return isRecord(evidence) ? evidence : void 0;
|
|
2640
|
-
}
|
|
2641
|
-
function summarizeLinkStatusEvidence(viewport, check) {
|
|
2642
|
-
const linkEvidence = linkStatusEvidenceForCheck(viewport, check);
|
|
2643
|
-
if (!linkEvidence) {
|
|
2644
|
-
return {
|
|
2645
|
-
viewport: viewport.name,
|
|
2646
|
-
selector: linkStatusSelector(check),
|
|
2647
|
-
total_count: 0,
|
|
2648
|
-
ok_count: 0,
|
|
2649
|
-
failed_count: 1,
|
|
2650
|
-
failures: [{ code: "link_status_evidence_missing" }]
|
|
2651
|
-
};
|
|
2652
|
-
}
|
|
2653
|
-
const results = Array.isArray(linkEvidence.results) ? linkEvidence.results.filter(isRecord) : [];
|
|
2654
|
-
const totalCount = numberValue(linkEvidence.total_count) ?? results.length;
|
|
2655
|
-
const resultCount = numberValue(linkEvidence.result_count) ?? totalCount;
|
|
2656
|
-
const storedResultCount = numberValue(linkEvidence.stored_result_count) ?? results.length;
|
|
2657
|
-
const omittedResultCount = numberValue(linkEvidence.omitted_result_count) ?? Math.max(0, resultCount - storedResultCount);
|
|
2658
|
-
const omittedSuccessCount = numberValue(linkEvidence.omitted_success_count) ?? 0;
|
|
2659
|
-
const okCount = results.filter((result) => linkStatusResultOk(result, check)).length;
|
|
2660
|
-
const failures = results.filter((result) => !linkStatusResultOk(result, check)).map((result) => ({
|
|
2661
|
-
code: "link_status_failed",
|
|
2662
|
-
url: stringValue(result.url) ?? null,
|
|
2663
|
-
status: numberValue(result.status) ?? null,
|
|
2664
|
-
method: stringValue(result.method) ?? null,
|
|
2665
|
-
error: stringValue(result.error) ?? null,
|
|
2666
|
-
content_type: stringValue(result.content_type) ?? null,
|
|
2667
|
-
bytes: linkStatusObservedBytes(result) ?? null,
|
|
2668
|
-
min_bytes: check.min_bytes ?? null,
|
|
2669
|
-
allowed_content_types: check.allowed_content_types ?? null
|
|
2670
|
-
}));
|
|
2671
|
-
if (stringValue(linkEvidence.error)) {
|
|
2672
|
-
failures.push({ code: "link_status_capture_failed", error: stringValue(linkEvidence.error) ?? "" });
|
|
2673
|
-
}
|
|
2674
|
-
const recordedFailedCount = numberValue(linkEvidence.failed_count) ?? 0;
|
|
2675
|
-
if (!failures.length && recordedFailedCount > 0) {
|
|
2676
|
-
const recordedFailures = Array.isArray(linkEvidence.failures) ? linkEvidence.failures.slice(0, 20) : [];
|
|
2677
|
-
failures.push({
|
|
2678
|
-
code: "link_status_recorded_failures",
|
|
2679
|
-
failed_count: recordedFailedCount,
|
|
2680
|
-
failures: toJsonValue(recordedFailures)
|
|
2681
|
-
});
|
|
2682
|
-
}
|
|
2683
|
-
if (linkEvidence.truncated === true) {
|
|
2684
|
-
failures.push({
|
|
2685
|
-
code: "link_status_probe_truncated",
|
|
2686
|
-
discovered_count: numberValue(linkEvidence.discovered_count) ?? totalCount,
|
|
2687
|
-
max_links: numberValue(linkEvidence.max_links) ?? check.max_links ?? 100
|
|
2688
|
-
});
|
|
2689
|
-
}
|
|
2690
|
-
if (check.expected_count !== void 0 && totalCount !== check.expected_count) {
|
|
2691
|
-
failures.push({ code: "link_status_count_mismatch", expected: check.expected_count, actual: totalCount });
|
|
2692
|
-
}
|
|
2693
|
-
if (check.min_count !== void 0 && totalCount < check.min_count) {
|
|
2694
|
-
failures.push({ code: "link_status_count_below_minimum", min_count: check.min_count, actual: totalCount });
|
|
2695
|
-
}
|
|
2696
|
-
const statusCounts = isRecord(linkEvidence.status_counts) ? linkEvidence.status_counts : {};
|
|
2697
|
-
return {
|
|
2698
|
-
viewport: viewport.name,
|
|
2699
|
-
selector: linkStatusSelector(check),
|
|
2700
|
-
total_count: totalCount,
|
|
2701
|
-
discovered_count: numberValue(linkEvidence.discovered_count) ?? totalCount,
|
|
2702
|
-
ok_count: numberValue(linkEvidence.ok_count) ?? okCount,
|
|
2703
|
-
failed_count: failures.length,
|
|
2704
|
-
truncated: linkEvidence.truncated === true,
|
|
2705
|
-
max_links: numberValue(linkEvidence.max_links) ?? check.max_links ?? 100,
|
|
2706
|
-
result_count: resultCount,
|
|
2707
|
-
stored_result_count: storedResultCount,
|
|
2708
|
-
omitted_result_count: omittedResultCount,
|
|
2709
|
-
omitted_success_count: omittedSuccessCount,
|
|
2710
|
-
results_compacted: linkEvidence.results_compacted === true || omittedResultCount > 0,
|
|
2711
|
-
min_bytes: check.min_bytes ?? null,
|
|
2712
|
-
allowed_content_types: check.allowed_content_types ?? null,
|
|
2713
|
-
status_counts: statusCounts,
|
|
2714
|
-
failures: failures.slice(0, 20)
|
|
2715
|
-
};
|
|
2716
|
-
}
|
|
2717
|
-
function textKey(check) {
|
|
2718
|
-
return check.pattern ? `pattern:${check.pattern}/${check.flags || ""}` : `text:${check.text || ""}`;
|
|
2719
|
-
}
|
|
2720
|
-
function observeWithinTimeoutMs(check) {
|
|
2721
|
-
const raw = check.timeout_ms;
|
|
2722
|
-
if (typeof raw === "number" && Number.isFinite(raw) && raw > 0) return Math.min(Math.round(raw), 6e4);
|
|
2723
|
-
return 2e3;
|
|
2724
|
-
}
|
|
2725
|
-
function observeWithinKey(check) {
|
|
2726
|
-
const target = check.selector ? `selector:${check.selector}` : "page";
|
|
2727
|
-
const expectation = check.pattern ? `pattern:${check.pattern}/${check.flags || ""}` : check.text ? `text:${check.text}` : "visible";
|
|
2728
|
-
return `${target}|${expectation}|within:${observeWithinTimeoutMs(check)}`;
|
|
2729
|
-
}
|
|
2730
|
-
function textSequenceForCheck(viewport, check) {
|
|
2731
|
-
const key = selectorKey(check);
|
|
2732
|
-
const sequence = viewport.text_sequences?.[key];
|
|
2733
|
-
if (isRecord(sequence)) {
|
|
2734
|
-
const visibleMatchTexts = Array.isArray(sequence.visible_match_texts) ? sequence.visible_match_texts : [];
|
|
2735
|
-
const matchTexts = Array.isArray(sequence.match_texts) ? sequence.match_texts : [];
|
|
2736
|
-
const visibleTexts = Array.isArray(sequence.visible_texts) ? sequence.visible_texts : [];
|
|
2737
|
-
const texts = Array.isArray(sequence.texts) ? sequence.texts : [];
|
|
2738
|
-
let candidates;
|
|
2739
|
-
if (check.type === "selector_text_visible") {
|
|
2740
|
-
candidates = visibleMatchTexts.length ? visibleMatchTexts : visibleTexts;
|
|
2741
|
-
} else if (check.type === "selector_text_absent") {
|
|
2742
|
-
candidates = matchTexts.length ? matchTexts : texts;
|
|
2743
|
-
} else {
|
|
2744
|
-
candidates = visibleMatchTexts.length ? visibleMatchTexts : matchTexts.length ? matchTexts : visibleTexts.length ? visibleTexts : texts;
|
|
2745
|
-
}
|
|
2746
|
-
return candidates.map((text) => String(text).replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
2747
|
-
}
|
|
2748
|
-
return [];
|
|
2749
|
-
}
|
|
2750
|
-
function textOrderMatch(texts, expectedTexts) {
|
|
2751
|
-
const positions = [];
|
|
2752
|
-
let startAt = 0;
|
|
2753
|
-
for (const expected of expectedTexts) {
|
|
2754
|
-
const index = texts.findIndex((text, offset) => offset >= startAt && text.includes(expected));
|
|
2755
|
-
if (index < 0) return { matched: false, positions };
|
|
2756
|
-
positions.push(index);
|
|
2757
|
-
startAt = index + 1;
|
|
2758
|
-
}
|
|
2759
|
-
return { matched: true, positions };
|
|
2760
|
-
}
|
|
2761
|
-
function frameEvidenceForSelector(viewport, selector) {
|
|
2762
|
-
const container = viewport.frames?.[selector];
|
|
2763
|
-
if (!isRecord(container)) return [];
|
|
2764
|
-
const frames = Array.isArray(container.frames) ? container.frames : [];
|
|
2765
|
-
return frames.filter((frame) => isRecord(frame));
|
|
2766
|
-
}
|
|
2767
|
-
function frameTextSample(frame) {
|
|
2768
|
-
const parts = [
|
|
2769
|
-
frame.title,
|
|
2770
|
-
frame.text_sample,
|
|
2771
|
-
frame.body_text_sample,
|
|
2772
|
-
frame.body_text,
|
|
2773
|
-
frame.text
|
|
2774
|
-
];
|
|
2775
|
-
return parts.map((part) => String(part || "")).filter(Boolean).join(" ");
|
|
2776
|
-
}
|
|
2777
|
-
function summarizeRouteInventory(viewport, inventory) {
|
|
2778
|
-
const directRoutes = Array.isArray(inventory.direct_routes) ? inventory.direct_routes : [];
|
|
2779
|
-
const clickthroughs = Array.isArray(inventory.clickthroughs) ? inventory.clickthroughs : [];
|
|
2780
|
-
const sourceLinkCount = numberValue(inventory.source_link_count) ?? numberValue(inventory.home_game_link_count) ?? null;
|
|
2781
|
-
const sourceUniqueLinkCount = numberValue(inventory.source_unique_link_count) ?? numberValue(inventory.home_unique_game_link_count) ?? null;
|
|
2782
|
-
const sourceCandidateCount = numberValue(inventory.source_candidate_count);
|
|
2783
|
-
const sourceCandidateUniqueLinkCount = numberValue(inventory.source_candidate_unique_link_count);
|
|
2784
|
-
const sourceLinkScope = stringValue(inventory.source_link_scope);
|
|
2785
|
-
const duplicateSourceLinks = Array.isArray(inventory.duplicate_source_link_paths) ? inventory.duplicate_source_link_paths.map((path) => String(path)) : [];
|
|
2786
|
-
const duplicateSourceLinkCount = numberValue(inventory.duplicate_source_link_count) ?? (sourceLinkCount !== null && sourceUniqueLinkCount !== null ? Math.max(0, sourceLinkCount - sourceUniqueLinkCount) : null);
|
|
2787
|
-
const failures = Array.isArray(inventory.failures) ? inventory.failures : [];
|
|
2788
|
-
return {
|
|
2789
|
-
viewport,
|
|
2790
|
-
source_link_scope: sourceLinkScope ?? null,
|
|
2791
|
-
source_candidate_count: sourceCandidateCount ?? sourceLinkCount,
|
|
2792
|
-
source_candidate_unique_link_count: sourceCandidateUniqueLinkCount ?? sourceUniqueLinkCount,
|
|
2793
|
-
source_link_count: sourceLinkCount,
|
|
2794
|
-
source_unique_link_count: sourceUniqueLinkCount,
|
|
2795
|
-
duplicate_source_link_count: duplicateSourceLinkCount,
|
|
2796
|
-
duplicate_source_links: duplicateSourceLinks,
|
|
2797
|
-
direct_route_count: directRoutes.length,
|
|
2798
|
-
clickthrough_count: clickthroughs.length,
|
|
2799
|
-
failure_count: failures.length
|
|
2800
|
-
};
|
|
2801
|
-
}
|
|
2802
|
-
function routeInventoryExpectedRouteSummaries(value, fallback) {
|
|
2803
|
-
const rawRoutes = Array.isArray(value) ? value : Array.isArray(fallback) ? fallback : [];
|
|
2804
|
-
return rawRoutes.map((route) => {
|
|
2805
|
-
if (typeof route === "string") {
|
|
2806
|
-
const path2 = route.trim();
|
|
2807
|
-
return path2 ? { path: path2 } : void 0;
|
|
2808
|
-
}
|
|
2809
|
-
if (!isRecord(route)) return void 0;
|
|
2810
|
-
const path = stringValue(route.path);
|
|
2811
|
-
if (!path) return void 0;
|
|
2812
|
-
const name = stringValue(route.name);
|
|
2813
|
-
return name ? { name, path } : { path };
|
|
2814
|
-
}).filter((route) => Boolean(route));
|
|
2815
|
-
}
|
|
2816
|
-
function matchText(sample, check) {
|
|
2817
|
-
if (check.pattern) {
|
|
2818
|
-
try {
|
|
2819
|
-
return new RegExp(check.pattern, check.flags || "").test(sample);
|
|
2820
|
-
} catch {
|
|
2821
|
-
return false;
|
|
2822
|
-
}
|
|
2823
|
-
}
|
|
2824
|
-
return sample.includes(check.text || "");
|
|
2825
|
-
}
|
|
2826
|
-
function compactTextEvidenceSample(value) {
|
|
2827
|
-
return String(value || "").replace(/\s+/g, " ").trim();
|
|
2828
|
-
}
|
|
2829
|
-
function textSampleAroundMatch(sample, index, length) {
|
|
2830
|
-
if (index < 0) return void 0;
|
|
2831
|
-
const source = String(sample || "");
|
|
2832
|
-
const context = 120;
|
|
2833
|
-
const start = Math.max(0, index - context);
|
|
2834
|
-
const end = Math.min(source.length, index + Math.max(length, 1) + context);
|
|
2835
|
-
const prefix = start > 0 ? "..." : "";
|
|
2836
|
-
const suffix = end < source.length ? "..." : "";
|
|
2837
|
-
const compacted = compactTextEvidenceSample(`${prefix}${source.slice(start, end)}${suffix}`);
|
|
2838
|
-
return compacted ? compacted.slice(0, 240) : void 0;
|
|
2839
|
-
}
|
|
2840
|
-
function textMatchSamples(sample, check) {
|
|
2841
|
-
const source = String(sample || "");
|
|
2842
|
-
if (!source) return [];
|
|
2843
|
-
if (check.pattern) {
|
|
2844
|
-
try {
|
|
2845
|
-
const flags = Array.from(new Set(String(check.flags || "").replace(/[gy]/g, "").split(""))).join("");
|
|
2846
|
-
const match = new RegExp(check.pattern, flags).exec(source);
|
|
2847
|
-
const sampleText2 = match ? textSampleAroundMatch(source, match.index, match[0]?.length || 1) : void 0;
|
|
2848
|
-
return sampleText2 ? [sampleText2] : [];
|
|
2849
|
-
} catch {
|
|
2850
|
-
return [];
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
const text = check.text || "";
|
|
2854
|
-
if (!text) return [];
|
|
2855
|
-
const index = source.indexOf(text);
|
|
2856
|
-
const sampleText = textSampleAroundMatch(source, index, text.length);
|
|
2857
|
-
return sampleText ? [sampleText] : [];
|
|
2858
|
-
}
|
|
2859
|
-
function textCaseInsensitiveSamples(sample, check) {
|
|
2860
|
-
const source = String(sample || "");
|
|
2861
|
-
const text = check.pattern ? "" : check.text || "";
|
|
2862
|
-
if (!source || !text) return [];
|
|
2863
|
-
const index = source.toLowerCase().indexOf(text.toLowerCase());
|
|
2864
|
-
const sampleText = textSampleAroundMatch(source, index, text.length);
|
|
2865
|
-
return sampleText ? [sampleText] : [];
|
|
2866
|
-
}
|
|
2867
|
-
function textCaseInsensitiveSequenceSamples(texts, check) {
|
|
2868
|
-
const text = check.pattern ? "" : compactTextEvidenceSample(check.text || "");
|
|
2869
|
-
if (!text) return [];
|
|
2870
|
-
const expected = text.toLowerCase();
|
|
2871
|
-
return texts.map((candidate) => compactTextEvidenceSample(candidate)).filter((candidate) => candidate && candidate.toLowerCase().includes(expected)).slice(0, 3).map((candidate) => candidate.slice(0, 240));
|
|
2872
|
-
}
|
|
2873
|
-
function textCaseInsensitiveFailureSamples(viewport, check) {
|
|
2874
|
-
const key = textKey(check);
|
|
2875
|
-
const captured = viewport.text_case_insensitive_samples?.[key] || [];
|
|
2876
|
-
const capturedSamples = captured.map((sample) => compactTextEvidenceSample(sample).slice(0, 240)).filter(Boolean);
|
|
2877
|
-
if (capturedSamples.length) return capturedSamples.slice(0, 3);
|
|
2878
|
-
return textCaseInsensitiveSamples(viewport.body_text_sample || "", check).slice(0, 3);
|
|
2879
|
-
}
|
|
2880
|
-
function textCheckFailureSamples(viewport, check) {
|
|
2881
|
-
const key = textKey(check);
|
|
2882
|
-
const captured = viewport.text_match_samples?.[key] || [];
|
|
2883
|
-
const capturedSamples = captured.map((sample) => compactTextEvidenceSample(sample).slice(0, 240)).filter(Boolean);
|
|
2884
|
-
if (capturedSamples.length) return capturedSamples.slice(0, 3);
|
|
2885
|
-
const matchedSamples = textMatchSamples(viewport.body_text_sample || "", check);
|
|
2886
|
-
if (matchedSamples.length) return matchedSamples.slice(0, 3);
|
|
2887
|
-
const fallback = compactTextEvidenceSample(viewport.body_text_sample || "").slice(0, 240);
|
|
2888
|
-
return fallback ? [fallback] : [];
|
|
2889
|
-
}
|
|
2890
|
-
function allowedMessageSample(input) {
|
|
2891
|
-
if (!isRecord(input)) return String(input || "");
|
|
2892
|
-
const parts = [
|
|
2893
|
-
input.text,
|
|
2894
|
-
input.message,
|
|
2895
|
-
isRecord(input.location) ? input.location.url : void 0
|
|
2896
|
-
];
|
|
2897
|
-
return parts.map((part) => String(part || "")).filter(Boolean).join(" ");
|
|
2898
|
-
}
|
|
2899
|
-
function matchesAllowedMessage(input, texts, patterns) {
|
|
2900
|
-
const sample = allowedMessageSample(input);
|
|
2901
|
-
if (texts?.some((text) => sample.includes(text))) return true;
|
|
2902
|
-
for (const pattern of patterns || []) {
|
|
2903
|
-
try {
|
|
2904
|
-
if (new RegExp(pattern).test(sample)) return true;
|
|
2905
|
-
} catch {
|
|
2906
|
-
continue;
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
return false;
|
|
2910
|
-
}
|
|
2911
|
-
function consoleEventLocationUrl(input) {
|
|
2912
|
-
if (!isRecord(input) || !isRecord(input.location)) return void 0;
|
|
2913
|
-
return stringValue(input.location.url);
|
|
2914
|
-
}
|
|
2915
|
-
function expectedFailedNetworkMockEvents(evidence) {
|
|
2916
|
-
return (evidence.network_mocks || []).filter((event) => {
|
|
2917
|
-
if (!isRecord(event) || event.ok === false) return false;
|
|
2918
|
-
const status = numberValue(event.status);
|
|
2919
|
-
const isHttpFailure = status !== void 0 && status >= 400;
|
|
2920
|
-
const isAbortedMock = event.abort === true && Boolean(stringValue(event.abort_error_code));
|
|
2921
|
-
return (isHttpFailure || isAbortedMock) && Boolean(stringValue(event.url));
|
|
2922
|
-
});
|
|
2923
|
-
}
|
|
2924
|
-
function matchingExpectedFailedNetworkMockConsoleEvent(event, evidence) {
|
|
2925
|
-
const sample = allowedMessageSample(event);
|
|
2926
|
-
if (!/Failed to load resource/i.test(sample)) return void 0;
|
|
2927
|
-
const eventUrl = consoleEventLocationUrl(event);
|
|
2928
|
-
if (!eventUrl) return void 0;
|
|
2929
|
-
return expectedFailedNetworkMockEvents(evidence).find((mockEvent) => {
|
|
2930
|
-
const status = numberValue(mockEvent.status);
|
|
2931
|
-
const abortErrorCode = stringValue(mockEvent.abort_error_code);
|
|
2932
|
-
return stringValue(mockEvent.url) === eventUrl && (status !== void 0 && sample.includes(String(status)) || Boolean(abortErrorCode) && /Failed to load resource/i.test(sample));
|
|
2933
|
-
});
|
|
2934
|
-
}
|
|
2935
|
-
function isExpectedFailedNetworkMockConsoleEvent(event, evidence) {
|
|
2936
|
-
return Boolean(matchingExpectedFailedNetworkMockConsoleEvent(event, evidence));
|
|
2937
|
-
}
|
|
2938
|
-
function expectedFailedNetworkMockConsoleEventSummary(event, evidence) {
|
|
2939
|
-
const match = matchingExpectedFailedNetworkMockConsoleEvent(event, evidence);
|
|
2940
|
-
const sample = allowedMessageSample(event);
|
|
2941
|
-
return {
|
|
2942
|
-
url: consoleEventLocationUrl(event) ?? null,
|
|
2943
|
-
status: match ? numberValue(match.status) ?? null : null,
|
|
2944
|
-
abort_error_code: match ? stringValue(match.abort_error_code) ?? null : null,
|
|
2945
|
-
label: match ? stringValue(match.label) ?? null : null,
|
|
2946
|
-
response_label: match ? stringValue(match.response_label) ?? null : null,
|
|
2947
|
-
text: isRecord(event) && typeof event.text === "string" ? event.text.slice(0, 300) : sample.slice(0, 300)
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
function normalizeRoutePath(path) {
|
|
2951
|
-
const value = path || "/";
|
|
2952
|
-
if (value === "/") return "/";
|
|
2953
|
-
return value.replace(/\/+$/, "") || "/";
|
|
2954
|
-
}
|
|
2955
|
-
function previewMountPrefix(pathname) {
|
|
2956
|
-
const value = pathname || "/";
|
|
2957
|
-
const apiPreview = value.match(/^(\/s\/[^/]+)(?:\/|$)/);
|
|
2958
|
-
if (apiPreview) return apiPreview[1];
|
|
2959
|
-
const internalPreview = value.match(/^(\/preview\/[^/]+\/[^/]+)(?:\/|$)/);
|
|
2960
|
-
return internalPreview ? internalPreview[1] : "";
|
|
2961
|
-
}
|
|
2962
|
-
function joinMountedRoutePath(mountPrefix, routePath) {
|
|
2963
|
-
const route = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
2964
|
-
if (!mountPrefix) return route;
|
|
2965
|
-
if (route === mountPrefix || route.startsWith(`${mountPrefix}/`)) return route;
|
|
2966
|
-
return `${mountPrefix}${route}`;
|
|
2967
|
-
}
|
|
2968
|
-
function resolveRiddleProofProfileRouteUrl(targetUrl, route) {
|
|
2969
|
-
if (/^https?:\/\//i.test(route)) return route;
|
|
2970
|
-
if (!targetUrl) return route;
|
|
2971
|
-
if (route.startsWith("/")) {
|
|
2972
|
-
const base = new URL(targetUrl);
|
|
2973
|
-
const mountPrefix = previewMountPrefix(base.pathname);
|
|
2974
|
-
if (mountPrefix) {
|
|
2975
|
-
const routeParts = new URL(route, base.origin);
|
|
2976
|
-
base.pathname = joinMountedRoutePath(mountPrefix, routeParts.pathname);
|
|
2977
|
-
base.search = routeParts.search;
|
|
2978
|
-
base.hash = routeParts.hash;
|
|
2979
|
-
return base.href;
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
return new URL(route, targetUrl).href;
|
|
2983
|
-
}
|
|
2984
|
-
function mountedExpectedRoutePath(targetUrl, expected) {
|
|
2985
|
-
if (!targetUrl || !expected || !expected.startsWith("/")) return expected;
|
|
2986
|
-
const mountPrefix = previewMountPrefix(new URL(targetUrl).pathname);
|
|
2987
|
-
return mountPrefix ? joinMountedRoutePath(mountPrefix, expected) : expected;
|
|
2988
|
-
}
|
|
2989
|
-
function routePathMatches(observed, expected, targetUrl) {
|
|
2990
|
-
const normalizedObserved = normalizeRoutePath(observed);
|
|
2991
|
-
const normalizedExpected = normalizeRoutePath(expected);
|
|
2992
|
-
if (normalizedObserved === normalizedExpected) return true;
|
|
2993
|
-
return normalizedObserved === normalizeRoutePath(mountedExpectedRoutePath(targetUrl, expected));
|
|
2994
|
-
}
|
|
2995
|
-
function successfulRoute(route, targetUrl) {
|
|
2996
|
-
const matched = route.matched || routePathMatches(route.observed, route.expected_path, targetUrl);
|
|
2997
|
-
return matched && !route.error && (route.http_status === null || route.http_status === void 0 || route.http_status < 400);
|
|
2998
|
-
}
|
|
2999
|
-
function routeReadinessFailed(route, targetUrl) {
|
|
3000
|
-
const matched = route.matched || routePathMatches(route.observed, route.expected_path, targetUrl);
|
|
3001
|
-
const httpOk = route.http_status === null || route.http_status === void 0 || route.http_status < 400;
|
|
3002
|
-
return matched && httpOk && Boolean(route.error);
|
|
3003
|
-
}
|
|
3004
|
-
function compactRouteError(error) {
|
|
3005
|
-
const text = typeof error === "string" ? error.replace(/\s+/g, " ").trim() : "";
|
|
3006
|
-
return text ? text.slice(0, 240) : void 0;
|
|
3007
|
-
}
|
|
3008
|
-
function routeLoadedFailureMessage(failedRoutes, expectedPath, targetUrl) {
|
|
3009
|
-
const readinessFailures = failedRoutes.filter((route) => routeReadinessFailed(route, targetUrl));
|
|
3010
|
-
if (readinessFailures.length === failedRoutes.length && readinessFailures.length) {
|
|
3011
|
-
const sample = compactRouteError(readinessFailures.find((route) => route.error)?.error);
|
|
3012
|
-
return `Route matched ${expectedPath}, but readiness failed in ${readinessFailures.length} viewport(s)${sample ? `: ${sample}` : "."}`;
|
|
3013
|
-
}
|
|
3014
|
-
if (readinessFailures.length) {
|
|
3015
|
-
const sample = compactRouteError(readinessFailures.find((route) => route.error)?.error);
|
|
3016
|
-
return `Route did not become ready as ${expectedPath} in ${failedRoutes.length} viewport(s); ${readinessFailures.length} matched path and HTTP but failed readiness${sample ? `: ${sample}` : "."}`;
|
|
3017
|
-
}
|
|
3018
|
-
return `Route did not load as ${expectedPath} in ${failedRoutes.length} viewport(s).`;
|
|
3019
|
-
}
|
|
3020
|
-
function parseEvidenceUrl(value, targetUrl) {
|
|
3021
|
-
if (!value) return void 0;
|
|
3022
|
-
try {
|
|
3023
|
-
return targetUrl ? new URL(value, targetUrl) : new URL(value);
|
|
3024
|
-
} catch {
|
|
3025
|
-
try {
|
|
3026
|
-
return new URL(value);
|
|
3027
|
-
} catch {
|
|
3028
|
-
return void 0;
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
function observedUrlForViewport(viewport, targetUrl) {
|
|
3033
|
-
return parseEvidenceUrl(viewport.url, targetUrl) || parseEvidenceUrl(viewport.route?.observed, targetUrl) || parseEvidenceUrl(viewport.route?.requested, targetUrl) || parseEvidenceUrl(targetUrl, void 0);
|
|
3034
|
-
}
|
|
3035
|
-
function searchParamObservation(viewport, targetUrl, param) {
|
|
3036
|
-
const url = observedUrlForViewport(viewport, targetUrl);
|
|
3037
|
-
const values = url ? url.searchParams.getAll(param) : [];
|
|
3038
|
-
return {
|
|
3039
|
-
viewport: viewport.name,
|
|
3040
|
-
url: url?.href || null,
|
|
3041
|
-
value: values.length ? values[0] : null,
|
|
3042
|
-
values,
|
|
3043
|
-
present: values.length > 0
|
|
3044
|
-
};
|
|
3045
|
-
}
|
|
3046
|
-
function viewportsForCheck(check, viewports) {
|
|
3047
|
-
if (!check.viewports?.length) return viewports;
|
|
3048
|
-
const names = new Set(check.viewports);
|
|
3049
|
-
return viewports.filter((viewport) => names.has(viewport.name));
|
|
3050
|
-
}
|
|
3051
|
-
function setupActionAppliesToViewport(action, viewportName) {
|
|
3052
|
-
if (!action.viewports?.length) return true;
|
|
3053
|
-
return Boolean(viewportName && action.viewports.includes(viewportName));
|
|
323
|
+
function httpStatusBodyNotContainsFailures(result, check) {
|
|
324
|
+
const forbidden = check.body_not_contains?.filter(Boolean) ?? [];
|
|
325
|
+
if (!forbidden.length) return [];
|
|
326
|
+
const observed = isRecord(result.body_not_contains) ? result.body_not_contains : {};
|
|
327
|
+
return forbidden.filter((text) => observed[text] !== false);
|
|
3054
328
|
}
|
|
3055
|
-
function
|
|
3056
|
-
|
|
329
|
+
function httpStatusBodyNotPatternFailures(result, check) {
|
|
330
|
+
const forbidden = check.body_not_patterns?.filter(Boolean) ?? [];
|
|
331
|
+
if (!forbidden.length) return [];
|
|
332
|
+
const observed = isRecord(result.body_not_patterns) ? result.body_not_patterns : {};
|
|
333
|
+
return forbidden.filter((pattern) => observed[pattern] !== false);
|
|
3057
334
|
}
|
|
3058
|
-
function
|
|
3059
|
-
const
|
|
3060
|
-
if (!
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
label:
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
};
|
|
3070
|
-
}
|
|
3071
|
-
if (isDialogCountCheckType(check.type)) {
|
|
3072
|
-
const field = dialogCountFieldForCheckType(check.type);
|
|
3073
|
-
const expectedCount = check.expected_count ?? 0;
|
|
3074
|
-
const actualCount = numberValue(evidence.dom_summary?.[field]) ?? 0;
|
|
3075
|
-
return {
|
|
3076
|
-
type: check.type,
|
|
3077
|
-
label: checkLabel(check),
|
|
3078
|
-
status: actualCount === expectedCount ? "passed" : "failed",
|
|
3079
|
-
evidence: {
|
|
3080
|
-
field,
|
|
3081
|
-
expected_count: expectedCount,
|
|
3082
|
-
count: actualCount
|
|
3083
|
-
},
|
|
3084
|
-
message: actualCount === expectedCount ? void 0 : `${field} did not equal ${expectedCount}; observed ${actualCount}.`
|
|
3085
|
-
};
|
|
3086
|
-
}
|
|
3087
|
-
if (check.type === "route_loaded") {
|
|
3088
|
-
const expectedPath = check.expected_path || new URL(evidence.target_url).pathname || "/";
|
|
3089
|
-
const routes = viewports.map((viewport) => ({
|
|
3090
|
-
...viewport.route,
|
|
3091
|
-
expected_path: expectedPath,
|
|
3092
|
-
matched: routePathMatches(viewport.route.observed, expectedPath, evidence.target_url) || viewport.route.matched
|
|
3093
|
-
}));
|
|
3094
|
-
const failed = routes.filter((route) => !successfulRoute(route, evidence.target_url));
|
|
3095
|
-
return {
|
|
3096
|
-
type: check.type,
|
|
3097
|
-
label: checkLabel(check),
|
|
3098
|
-
status: failed.length ? "failed" : "passed",
|
|
3099
|
-
evidence: {
|
|
3100
|
-
expected_path: expectedPath,
|
|
3101
|
-
observed_paths: viewports.map((viewport) => viewport.route.observed),
|
|
3102
|
-
http_statuses: viewports.map((viewport) => viewport.route.http_status ?? null),
|
|
3103
|
-
route_errors: viewports.map((viewport) => viewport.route.error ?? null)
|
|
3104
|
-
},
|
|
3105
|
-
message: failed.length ? routeLoadedFailureMessage(failed, expectedPath, evidence.target_url) : void 0
|
|
3106
|
-
};
|
|
3107
|
-
}
|
|
3108
|
-
if (check.type === "url_search_param_equals") {
|
|
3109
|
-
const param = check.param || "";
|
|
3110
|
-
const expectedValue = check.expected_value ?? "";
|
|
3111
|
-
const observations = viewports.map((viewport) => searchParamObservation(viewport, evidence.target_url, param));
|
|
3112
|
-
const failed = observations.filter((observation) => observation.value !== expectedValue);
|
|
3113
|
-
return {
|
|
3114
|
-
type: check.type,
|
|
3115
|
-
label: checkLabel(check),
|
|
3116
|
-
status: failed.length ? "failed" : "passed",
|
|
3117
|
-
evidence: {
|
|
3118
|
-
param,
|
|
3119
|
-
expected_value: expectedValue,
|
|
3120
|
-
observed_values: observations.map((observation) => observation.value),
|
|
3121
|
-
observed_all_values: observations.map((observation) => observation.values),
|
|
3122
|
-
observed_urls: observations.map((observation) => observation.url),
|
|
3123
|
-
viewports: observations.map((observation) => toJsonValue(observation))
|
|
3124
|
-
},
|
|
3125
|
-
message: failed.length ? `URL search param ${param} did not equal ${JSON.stringify(expectedValue)} in ${failed.length} viewport(s).` : void 0
|
|
3126
|
-
};
|
|
3127
|
-
}
|
|
3128
|
-
if (check.type === "url_search_param_absent") {
|
|
3129
|
-
const param = check.param || "";
|
|
3130
|
-
const observations = viewports.map((viewport) => searchParamObservation(viewport, evidence.target_url, param));
|
|
3131
|
-
const failed = observations.filter((observation) => observation.present);
|
|
3132
|
-
return {
|
|
3133
|
-
type: check.type,
|
|
3134
|
-
label: checkLabel(check),
|
|
3135
|
-
status: failed.length ? "failed" : "passed",
|
|
3136
|
-
evidence: {
|
|
3137
|
-
param,
|
|
3138
|
-
observed_values: observations.map((observation) => observation.value),
|
|
3139
|
-
observed_all_values: observations.map((observation) => observation.values),
|
|
3140
|
-
observed_urls: observations.map((observation) => observation.url),
|
|
3141
|
-
viewports: observations.map((observation) => toJsonValue(observation))
|
|
3142
|
-
},
|
|
3143
|
-
message: failed.length ? `URL search param ${param} was present in ${failed.length} viewport(s).` : void 0
|
|
3144
|
-
};
|
|
3145
|
-
}
|
|
3146
|
-
if (check.type === "selector_visible") {
|
|
3147
|
-
const key = selectorKey(check);
|
|
3148
|
-
const failed = viewports.filter((viewport) => (viewport.selectors?.[key]?.visible_count || 0) < 1);
|
|
3149
|
-
return {
|
|
3150
|
-
type: check.type,
|
|
3151
|
-
label: checkLabel(check),
|
|
3152
|
-
status: failed.length ? "failed" : "passed",
|
|
3153
|
-
evidence: {
|
|
3154
|
-
selector: key,
|
|
3155
|
-
visible_counts: viewports.map((viewport) => viewport.selectors?.[key]?.visible_count || 0)
|
|
3156
|
-
},
|
|
3157
|
-
message: failed.length ? `Selector ${key} was not visible in ${failed.length} viewport(s).` : void 0
|
|
3158
|
-
};
|
|
3159
|
-
}
|
|
3160
|
-
if (check.type === "selector_absent") {
|
|
3161
|
-
const key = selectorKey(check);
|
|
3162
|
-
const failed = viewports.filter((viewport) => (viewport.selectors?.[key]?.count || 0) > 0);
|
|
3163
|
-
return {
|
|
3164
|
-
type: check.type,
|
|
3165
|
-
label: checkLabel(check),
|
|
3166
|
-
status: failed.length ? "failed" : "passed",
|
|
3167
|
-
evidence: {
|
|
3168
|
-
selector: key,
|
|
3169
|
-
counts: viewports.map((viewport) => viewport.selectors?.[key]?.count || 0)
|
|
3170
|
-
},
|
|
3171
|
-
message: failed.length ? `Selector ${key} was present in ${failed.length} viewport(s).` : void 0
|
|
3172
|
-
};
|
|
3173
|
-
}
|
|
3174
|
-
if (check.type === "selector_count_at_least") {
|
|
3175
|
-
const key = selectorKey(check);
|
|
3176
|
-
const minCount = check.min_count ?? 1;
|
|
3177
|
-
const failed = viewports.filter((viewport) => (viewport.selectors?.[key]?.count || 0) < minCount);
|
|
3178
|
-
return {
|
|
3179
|
-
type: check.type,
|
|
3180
|
-
label: checkLabel(check),
|
|
3181
|
-
status: failed.length ? "failed" : "passed",
|
|
3182
|
-
evidence: {
|
|
3183
|
-
selector: key,
|
|
3184
|
-
min_count: minCount,
|
|
3185
|
-
counts: viewports.map((viewport) => viewport.selectors?.[key]?.count || 0)
|
|
3186
|
-
},
|
|
3187
|
-
message: failed.length ? `Selector ${key} count was below ${minCount} in ${failed.length} viewport(s).` : void 0
|
|
3188
|
-
};
|
|
3189
|
-
}
|
|
3190
|
-
if (check.type === "selector_count_equals" || check.type === "selector_count_equal" || check.type === "selector_count_eq") {
|
|
3191
|
-
const key = selectorKey(check);
|
|
3192
|
-
const expectedCount = check.expected_count ?? 0;
|
|
3193
|
-
const failed = viewports.filter((viewport) => (viewport.selectors?.[key]?.count || 0) !== expectedCount);
|
|
3194
|
-
return {
|
|
3195
|
-
type: check.type,
|
|
3196
|
-
label: checkLabel(check),
|
|
3197
|
-
status: failed.length ? "failed" : "passed",
|
|
3198
|
-
evidence: {
|
|
3199
|
-
selector: key,
|
|
3200
|
-
expected_count: expectedCount,
|
|
3201
|
-
counts: viewports.map((viewport) => viewport.selectors?.[key]?.count || 0)
|
|
3202
|
-
},
|
|
3203
|
-
message: failed.length ? `Selector ${key} count did not equal ${expectedCount} in ${failed.length} viewport(s).` : void 0
|
|
3204
|
-
};
|
|
3205
|
-
}
|
|
3206
|
-
if (check.type === "selector_text_visible" || check.type === "selector_text_absent") {
|
|
3207
|
-
const key = selectorKey(check);
|
|
3208
|
-
const expectedVisible = check.type === "selector_text_visible";
|
|
3209
|
-
const results = viewports.map((viewport) => {
|
|
3210
|
-
const texts = textSequenceForCheck(viewport, check);
|
|
3211
|
-
const matches = texts.filter((text) => matchText(text, check));
|
|
3212
|
-
const matched = matches.length > 0;
|
|
3213
|
-
const failedAgainstExpectation = matched !== expectedVisible;
|
|
3214
|
-
const sampleTexts = matches.length ? matches : failedAgainstExpectation ? texts : [];
|
|
3215
|
-
const caseInsensitiveSamples = failedAgainstExpectation && expectedVisible && !matched ? textCaseInsensitiveSequenceSamples(texts, check) : [];
|
|
3216
|
-
return {
|
|
3217
|
-
viewport: viewport.name,
|
|
3218
|
-
selector_count: viewport.selectors?.[key]?.count || 0,
|
|
3219
|
-
visible_count: viewport.selectors?.[key]?.visible_count || 0,
|
|
3220
|
-
matched_count: matches.length,
|
|
3221
|
-
matched,
|
|
3222
|
-
samples: sampleTexts.slice(0, 3).map((text) => text.slice(0, 240)),
|
|
3223
|
-
case_insensitive_samples: caseInsensitiveSamples
|
|
3224
|
-
};
|
|
3225
|
-
});
|
|
3226
|
-
const failed = results.filter((result) => result.matched !== expectedVisible).length;
|
|
3227
|
-
return {
|
|
3228
|
-
type: check.type,
|
|
3229
|
-
label: checkLabel(check),
|
|
3230
|
-
status: failed ? "failed" : "passed",
|
|
3231
|
-
evidence: {
|
|
3232
|
-
selector: key,
|
|
3233
|
-
text: check.text || null,
|
|
3234
|
-
pattern: check.pattern || null,
|
|
3235
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3236
|
-
},
|
|
3237
|
-
message: failed ? `Selector ${key} text assertion failed in ${failed} viewport(s).` : void 0
|
|
3238
|
-
};
|
|
3239
|
-
}
|
|
3240
|
-
if (check.type === "selector_text_order") {
|
|
3241
|
-
const key = selectorKey(check);
|
|
3242
|
-
const expectedTexts = check.expected_texts || [];
|
|
3243
|
-
const results = viewports.map((viewport) => {
|
|
3244
|
-
const texts = textSequenceForCheck(viewport, check);
|
|
3245
|
-
const match = textOrderMatch(texts, expectedTexts);
|
|
3246
|
-
return {
|
|
3247
|
-
viewport: viewport.name,
|
|
3248
|
-
matched: match.matched,
|
|
3249
|
-
matched_positions: match.positions,
|
|
3250
|
-
visible_texts: texts.slice(0, 20).map((text) => text.slice(0, 240))
|
|
3251
|
-
};
|
|
3252
|
-
});
|
|
3253
|
-
const failed = results.filter((result) => !result.matched).length;
|
|
3254
|
-
return {
|
|
3255
|
-
type: check.type,
|
|
3256
|
-
label: checkLabel(check),
|
|
3257
|
-
status: failed ? "failed" : "passed",
|
|
3258
|
-
evidence: {
|
|
3259
|
-
selector: key,
|
|
3260
|
-
expected_texts: expectedTexts,
|
|
3261
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3262
|
-
},
|
|
3263
|
-
message: failed ? `Selector ${key} text order failed in ${failed} viewport(s).` : void 0
|
|
3264
|
-
};
|
|
3265
|
-
}
|
|
3266
|
-
if (check.type === "ordered_trace") {
|
|
3267
|
-
const assessments = viewports.map((viewport) => ({
|
|
3268
|
-
viewport: viewport.name,
|
|
3269
|
-
assessment: assessRiddleProofOrderedTraceSetupResults(
|
|
3270
|
-
viewport.setup_action_results,
|
|
3271
|
-
check.setup_action_label || "",
|
|
3272
|
-
check.trace_path || "",
|
|
3273
|
-
check.events || []
|
|
3274
|
-
)
|
|
335
|
+
function httpStatusBodyJsonAssertionFailures(result, check) {
|
|
336
|
+
const expected = check.body_json_assertions?.filter((assertion) => assertion.path) ?? [];
|
|
337
|
+
if (!expected.length) return [];
|
|
338
|
+
if (!Array.isArray(result.body_json_assertions)) {
|
|
339
|
+
return expected.map((assertion) => ({
|
|
340
|
+
label: assertion.label || assertion.path,
|
|
341
|
+
path: assertion.path,
|
|
342
|
+
ok: false,
|
|
343
|
+
exists: false,
|
|
344
|
+
observed_type: "missing",
|
|
345
|
+
errors: ["body_json_assertions evidence missing"]
|
|
3275
346
|
}));
|
|
3276
|
-
const insufficient = assessments.filter((item) => item.assessment.status === "proof_insufficient");
|
|
3277
|
-
const failed = assessments.filter((item) => item.assessment.status === "failed");
|
|
3278
|
-
const status = insufficient.length ? "proof_insufficient" : failed.length ? "failed" : "passed";
|
|
3279
|
-
return {
|
|
3280
|
-
type: check.type,
|
|
3281
|
-
label: checkLabel(check),
|
|
3282
|
-
status,
|
|
3283
|
-
evidence: {
|
|
3284
|
-
setup_action_label: check.setup_action_label || "",
|
|
3285
|
-
trace_path: check.trace_path || "",
|
|
3286
|
-
events: toJsonValue((check.events || []).map((event) => event.label)),
|
|
3287
|
-
viewports: toJsonValue(assessments)
|
|
3288
|
-
},
|
|
3289
|
-
message: insufficient.length ? `Ordered trace evidence was insufficient in ${insufficient.length} viewport(s).` : failed.length ? `Ordered trace did not contain the required event sequence in ${failed.length} viewport(s).` : void 0
|
|
3290
|
-
};
|
|
3291
|
-
}
|
|
3292
|
-
if (check.type === "observe_within") {
|
|
3293
|
-
const key = observeWithinKey(check);
|
|
3294
|
-
const timeoutMs = observeWithinTimeoutMs(check);
|
|
3295
|
-
const results = viewports.map((viewport) => {
|
|
3296
|
-
const observation = viewport.observations?.[key];
|
|
3297
|
-
const matched = observation?.matched === true;
|
|
3298
|
-
return {
|
|
3299
|
-
viewport: viewport.name,
|
|
3300
|
-
matched,
|
|
3301
|
-
elapsed_ms: numberValue(observation?.elapsed_ms) ?? null,
|
|
3302
|
-
timeout_ms: numberValue(observation?.timeout_ms) ?? timeoutMs,
|
|
3303
|
-
attempts: numberValue(observation?.attempts) ?? null,
|
|
3304
|
-
selector_count: numberValue(observation?.selector_count) ?? null,
|
|
3305
|
-
visible_count: numberValue(observation?.visible_count) ?? null,
|
|
3306
|
-
matched_count: numberValue(observation?.matched_count) ?? null,
|
|
3307
|
-
sample: stringValue(observation?.sample) ?? null,
|
|
3308
|
-
error: stringValue(observation?.error) ?? null
|
|
3309
|
-
};
|
|
3310
|
-
});
|
|
3311
|
-
const failed = results.filter((result) => !result.matched).length;
|
|
3312
|
-
return {
|
|
3313
|
-
type: check.type,
|
|
3314
|
-
label: checkLabel(check),
|
|
3315
|
-
status: failed ? "failed" : "passed",
|
|
3316
|
-
evidence: {
|
|
3317
|
-
selector: check.selector || null,
|
|
3318
|
-
text: check.text || null,
|
|
3319
|
-
pattern: check.pattern || null,
|
|
3320
|
-
timeout_ms: timeoutMs,
|
|
3321
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3322
|
-
},
|
|
3323
|
-
message: failed ? `Observation did not match within ${timeoutMs}ms in ${failed} viewport(s).` : void 0
|
|
3324
|
-
};
|
|
3325
|
-
}
|
|
3326
|
-
if (check.type === "frame_text_visible") {
|
|
3327
|
-
const key = selectorKey(check);
|
|
3328
|
-
const results = viewports.map((viewport) => {
|
|
3329
|
-
const frames = frameEvidenceForSelector(viewport, key);
|
|
3330
|
-
const matches = frames.map((frame, index) => ({ index, frame, matched: matchText(frameTextSample(frame), check) })).filter((item) => item.matched);
|
|
3331
|
-
return {
|
|
3332
|
-
viewport: viewport.name,
|
|
3333
|
-
frame_count: frames.length,
|
|
3334
|
-
matched_count: matches.length,
|
|
3335
|
-
matched: matches.length > 0,
|
|
3336
|
-
urls: frames.map((frame) => String(frame.url || "")).filter(Boolean).slice(0, 10),
|
|
3337
|
-
samples: matches.map((item) => frameTextSample(item.frame).replace(/\s+/g, " ").trim().slice(0, 240)).slice(0, 3)
|
|
3338
|
-
};
|
|
3339
|
-
});
|
|
3340
|
-
const failed = results.filter((result) => !result.matched).length;
|
|
3341
|
-
return {
|
|
3342
|
-
type: check.type,
|
|
3343
|
-
label: checkLabel(check),
|
|
3344
|
-
status: failed ? "failed" : "passed",
|
|
3345
|
-
evidence: {
|
|
3346
|
-
selector: key,
|
|
3347
|
-
text: check.text || null,
|
|
3348
|
-
pattern: check.pattern || null,
|
|
3349
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3350
|
-
},
|
|
3351
|
-
message: failed ? `Frame selector ${key} did not contain expected text in ${failed} viewport(s).` : void 0
|
|
3352
|
-
};
|
|
3353
|
-
}
|
|
3354
|
-
if (check.type === "frame_url_equals" || check.type === "frame_url_matches") {
|
|
3355
|
-
const key = selectorKey(check);
|
|
3356
|
-
const expectedUrl = check.expected_url || check.expected_value || "";
|
|
3357
|
-
const results = viewports.map((viewport) => {
|
|
3358
|
-
const frames = frameEvidenceForSelector(viewport, key);
|
|
3359
|
-
const urls = frames.map((frame) => String(frame.url || "")).filter(Boolean);
|
|
3360
|
-
const matches = urls.filter((url) => check.type === "frame_url_equals" ? url === expectedUrl : matchText(url, check));
|
|
3361
|
-
return {
|
|
3362
|
-
viewport: viewport.name,
|
|
3363
|
-
frame_count: frames.length,
|
|
3364
|
-
matched_count: matches.length,
|
|
3365
|
-
matched: matches.length > 0,
|
|
3366
|
-
urls: urls.slice(0, 10)
|
|
3367
|
-
};
|
|
3368
|
-
});
|
|
3369
|
-
const failed = results.filter((result) => !result.matched).length;
|
|
3370
|
-
return {
|
|
3371
|
-
type: check.type,
|
|
3372
|
-
label: checkLabel(check),
|
|
3373
|
-
status: failed ? "failed" : "passed",
|
|
3374
|
-
evidence: {
|
|
3375
|
-
selector: key,
|
|
3376
|
-
expected_url: check.type === "frame_url_equals" ? expectedUrl : null,
|
|
3377
|
-
pattern: check.type === "frame_url_matches" ? check.pattern || null : null,
|
|
3378
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3379
|
-
},
|
|
3380
|
-
message: failed ? `Frame selector ${key} URL assertion failed in ${failed} viewport(s).` : void 0
|
|
3381
|
-
};
|
|
3382
|
-
}
|
|
3383
|
-
if (check.type === "frame_no_horizontal_overflow") {
|
|
3384
|
-
const key = selectorKey(check);
|
|
3385
|
-
const maxOverflow = check.max_overflow_px ?? 4;
|
|
3386
|
-
const results = viewports.map((viewport) => {
|
|
3387
|
-
const frames = frameEvidenceForSelector(viewport, key);
|
|
3388
|
-
const frameOverflows = frames.map((frame, index) => ({
|
|
3389
|
-
index,
|
|
3390
|
-
url: String(frame.url || ""),
|
|
3391
|
-
overflow_px: horizontalBoundsOverflowPx(frame),
|
|
3392
|
-
offender_count: boundsOffendersForEvidence(frame).length
|
|
3393
|
-
}));
|
|
3394
|
-
const maxFrameOverflow = frameOverflows.reduce((max, frame) => Math.max(max, frame.overflow_px), 0);
|
|
3395
|
-
return {
|
|
3396
|
-
viewport: viewport.name,
|
|
3397
|
-
frame_count: frames.length,
|
|
3398
|
-
max_overflow_px: roundPixels(maxFrameOverflow),
|
|
3399
|
-
failed_frame_count: frameOverflows.filter((frame) => frame.overflow_px > maxOverflow).length,
|
|
3400
|
-
frames: frameOverflows.map((frame) => toJsonValue(frame))
|
|
3401
|
-
};
|
|
3402
|
-
});
|
|
3403
|
-
const failed = results.filter((result) => result.frame_count < 1 || result.failed_frame_count > 0).length;
|
|
3404
|
-
return {
|
|
3405
|
-
type: check.type,
|
|
3406
|
-
label: checkLabel(check),
|
|
3407
|
-
status: failed ? "failed" : "passed",
|
|
3408
|
-
evidence: {
|
|
3409
|
-
selector: key,
|
|
3410
|
-
max_overflow_px: maxOverflow,
|
|
3411
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3412
|
-
},
|
|
3413
|
-
message: failed ? `Frame selector ${key} overflow exceeded ${maxOverflow}px or was missing in ${failed} viewport(s).` : void 0
|
|
3414
|
-
};
|
|
3415
|
-
}
|
|
3416
|
-
if (check.type === "text_visible" || check.type === "text_absent") {
|
|
3417
|
-
const key = textKey(check);
|
|
3418
|
-
const expectedVisible = check.type === "text_visible";
|
|
3419
|
-
const results = viewports.map((viewport) => {
|
|
3420
|
-
const fromEvidence = viewport.text_matches?.[key];
|
|
3421
|
-
const matched = typeof fromEvidence === "boolean" ? fromEvidence : matchText(viewport.body_text_sample || "", check);
|
|
3422
|
-
const failedAgainstExpectation = matched !== expectedVisible;
|
|
3423
|
-
return {
|
|
3424
|
-
viewport: viewport.name,
|
|
3425
|
-
matched,
|
|
3426
|
-
samples: failedAgainstExpectation ? textCheckFailureSamples(viewport, check) : [],
|
|
3427
|
-
case_insensitive_samples: failedAgainstExpectation && expectedVisible && !matched ? textCaseInsensitiveFailureSamples(viewport, check) : []
|
|
3428
|
-
};
|
|
3429
|
-
});
|
|
3430
|
-
const matches = results.map((result) => result.matched);
|
|
3431
|
-
const failed = matches.filter((matched) => matched !== expectedVisible).length;
|
|
3432
|
-
return {
|
|
3433
|
-
type: check.type,
|
|
3434
|
-
label: checkLabel(check),
|
|
3435
|
-
status: failed ? "failed" : "passed",
|
|
3436
|
-
evidence: {
|
|
3437
|
-
text: check.text || null,
|
|
3438
|
-
pattern: check.pattern || null,
|
|
3439
|
-
matches,
|
|
3440
|
-
viewports: results.map((result) => toJsonValue(result))
|
|
3441
|
-
},
|
|
3442
|
-
message: failed ? `Text assertion failed in ${failed} viewport(s).` : void 0
|
|
3443
|
-
};
|
|
3444
|
-
}
|
|
3445
|
-
if (check.type === "http_status") {
|
|
3446
|
-
const url = httpStatusRequestUrl(check, evidence.target_url);
|
|
3447
|
-
const method = httpStatusMethod(check);
|
|
3448
|
-
const summaries = viewports.map((viewport) => summarizeHttpStatusEvidence(viewport, check));
|
|
3449
|
-
const failed = summaries.filter((summary) => Array.isArray(summary.failures) && summary.failures.length > 0);
|
|
3450
|
-
return {
|
|
3451
|
-
type: check.type,
|
|
3452
|
-
label: checkLabel(check),
|
|
3453
|
-
status: failed.length ? "failed" : "passed",
|
|
3454
|
-
evidence: {
|
|
3455
|
-
url,
|
|
3456
|
-
method,
|
|
3457
|
-
allowed_statuses: httpStatusAllowedStatuses(check) || ["2xx", "3xx"],
|
|
3458
|
-
require_nonzero_bytes: check.require_nonzero_bytes === true,
|
|
3459
|
-
min_bytes: check.min_bytes ?? null,
|
|
3460
|
-
allowed_content_types: check.allowed_content_types ?? null,
|
|
3461
|
-
body_contains: check.body_contains ?? [],
|
|
3462
|
-
body_not_contains: check.body_not_contains ?? [],
|
|
3463
|
-
body_not_patterns: check.body_not_patterns ?? [],
|
|
3464
|
-
body_json_assertions: toJsonValue(check.body_json_assertions ?? []),
|
|
3465
|
-
viewports: summaries.map((summary) => toJsonValue(summary)),
|
|
3466
|
-
failures: failed.flatMap((summary) => Array.isArray(summary.failures) ? summary.failures.map((failure) => toJsonValue({ viewport: stringValue(summary.viewport) ?? null, failure })) : [])
|
|
3467
|
-
},
|
|
3468
|
-
message: failed.length ? `HTTP status failed in ${failed.length} viewport(s).` : void 0
|
|
3469
|
-
};
|
|
3470
|
-
}
|
|
3471
|
-
if (check.type === "link_status" || check.type === "artifact_link_status") {
|
|
3472
|
-
const selector = linkStatusSelector(check);
|
|
3473
|
-
const summaries = viewports.map((viewport) => summarizeLinkStatusEvidence(viewport, check));
|
|
3474
|
-
const failed = summaries.filter((summary) => (numberValue(summary.failed_count) ?? 0) > 0);
|
|
3475
|
-
return {
|
|
3476
|
-
type: check.type,
|
|
3477
|
-
label: checkLabel(check),
|
|
3478
|
-
status: failed.length ? "failed" : "passed",
|
|
3479
|
-
evidence: {
|
|
3480
|
-
selector,
|
|
3481
|
-
expected_count: check.expected_count ?? null,
|
|
3482
|
-
min_count: check.min_count ?? null,
|
|
3483
|
-
allowed_statuses: linkStatusAllowedStatuses(check) || ["2xx", "3xx"],
|
|
3484
|
-
require_nonzero_bytes: check.require_nonzero_bytes === true,
|
|
3485
|
-
min_bytes: check.min_bytes ?? null,
|
|
3486
|
-
allowed_content_types: check.allowed_content_types ?? null,
|
|
3487
|
-
viewports: summaries.map((summary) => toJsonValue(summary)),
|
|
3488
|
-
failures: failed.flatMap((summary) => Array.isArray(summary.failures) ? summary.failures.map((failure) => toJsonValue({ viewport: stringValue(summary.viewport) ?? null, failure })) : [])
|
|
3489
|
-
},
|
|
3490
|
-
message: failed.length ? `Link status failed in ${failed.length} viewport(s).` : void 0
|
|
3491
|
-
};
|
|
3492
|
-
}
|
|
3493
|
-
if (check.type === "route_inventory") {
|
|
3494
|
-
const inventories = viewports.map((viewport) => ({ viewport: viewport.name, inventory: viewport.route_inventory })).filter((item) => isRecord(item.inventory));
|
|
3495
|
-
if (!inventories.length) {
|
|
3496
|
-
return {
|
|
3497
|
-
type: check.type,
|
|
3498
|
-
label: checkLabel(check),
|
|
3499
|
-
status: "failed",
|
|
3500
|
-
evidence: {
|
|
3501
|
-
expected_count: check.expected_routes?.length || 0,
|
|
3502
|
-
expected_routes: routeInventoryExpectedRouteSummaries(void 0, check.expected_routes)
|
|
3503
|
-
},
|
|
3504
|
-
message: "No route inventory evidence was captured."
|
|
3505
|
-
};
|
|
3506
|
-
}
|
|
3507
|
-
const viewportSummaries = inventories.map((item) => summarizeRouteInventory(item.viewport, item.inventory));
|
|
3508
|
-
const failures = inventories.flatMap((item) => Array.isArray(item.inventory?.failures) ? item.inventory.failures.map((failure) => toJsonValue({ viewport: item.viewport, failure })) : []);
|
|
3509
|
-
const first = inventories[0]?.inventory;
|
|
3510
|
-
const directRoutes = Array.isArray(first?.direct_routes) ? first.direct_routes : [];
|
|
3511
|
-
const clickthroughs = Array.isArray(first?.clickthroughs) ? first.clickthroughs : [];
|
|
3512
|
-
const sourceLinkCount = numberValue(first?.source_link_count) ?? numberValue(first?.home_game_link_count) ?? null;
|
|
3513
|
-
const sourceUniqueLinkCount = numberValue(first?.source_unique_link_count) ?? numberValue(first?.home_unique_game_link_count) ?? null;
|
|
3514
|
-
const sourceCandidateCount = numberValue(first?.source_candidate_count);
|
|
3515
|
-
const sourceCandidateUniqueLinkCount = numberValue(first?.source_candidate_unique_link_count);
|
|
3516
|
-
const sourceLinkScope = stringValue(first?.source_link_scope);
|
|
3517
|
-
const duplicateSourceLinks = Array.isArray(first?.duplicate_source_link_paths) ? first.duplicate_source_link_paths.map((path) => String(path)) : [];
|
|
3518
|
-
const duplicateSourceLinkCount = numberValue(first?.duplicate_source_link_count) ?? (sourceLinkCount !== null && sourceUniqueLinkCount !== null ? Math.max(0, sourceLinkCount - sourceUniqueLinkCount) : null);
|
|
3519
|
-
const expectedRoutes = routeInventoryExpectedRouteSummaries(first?.expected_routes, check.expected_routes);
|
|
3520
|
-
return {
|
|
3521
|
-
type: check.type,
|
|
3522
|
-
label: checkLabel(check),
|
|
3523
|
-
status: failures.length ? "failed" : "passed",
|
|
3524
|
-
evidence: {
|
|
3525
|
-
expected_count: check.expected_routes?.length || 0,
|
|
3526
|
-
expected_routes: expectedRoutes,
|
|
3527
|
-
source_link_scope: sourceLinkScope ?? null,
|
|
3528
|
-
source_candidate_count: sourceCandidateCount ?? sourceLinkCount,
|
|
3529
|
-
source_candidate_unique_link_count: sourceCandidateUniqueLinkCount ?? sourceUniqueLinkCount,
|
|
3530
|
-
source_link_count: sourceLinkCount,
|
|
3531
|
-
source_unique_link_count: sourceUniqueLinkCount,
|
|
3532
|
-
duplicate_source_link_count: duplicateSourceLinkCount,
|
|
3533
|
-
duplicate_source_links: duplicateSourceLinks,
|
|
3534
|
-
duplicates_allowed: check.require_unique_routes === false,
|
|
3535
|
-
homepage_link_count: numberValue(first?.home_game_link_count) ?? sourceLinkCount,
|
|
3536
|
-
homepage_unique_link_count: numberValue(first?.home_unique_game_link_count) ?? sourceUniqueLinkCount,
|
|
3537
|
-
direct_route_count: directRoutes.length,
|
|
3538
|
-
clickthrough_count: clickthroughs.length,
|
|
3539
|
-
viewport_count: inventories.length,
|
|
3540
|
-
viewports: viewportSummaries.map((summary) => toJsonValue(summary)),
|
|
3541
|
-
failures
|
|
3542
|
-
},
|
|
3543
|
-
message: failures.length ? `Route inventory failed with ${failures.length} issue(s).` : void 0
|
|
3544
|
-
};
|
|
3545
|
-
}
|
|
3546
|
-
if (check.type === "no_horizontal_overflow" || check.type === "no_mobile_horizontal_overflow") {
|
|
3547
|
-
const maxOverflow = check.max_overflow_px ?? 4;
|
|
3548
|
-
const applicable = check.type === "no_mobile_horizontal_overflow" ? viewports.filter((viewport) => viewport.width <= 820) : viewports;
|
|
3549
|
-
if (!applicable.length) {
|
|
3550
|
-
const mobileOnly = check.type === "no_mobile_horizontal_overflow";
|
|
3551
|
-
return {
|
|
3552
|
-
type: check.type,
|
|
3553
|
-
label: checkLabel(check),
|
|
3554
|
-
status: mobileOnly ? "skipped" : "failed",
|
|
3555
|
-
evidence: { max_overflow_px: maxOverflow, viewports: [] },
|
|
3556
|
-
message: mobileOnly ? "No mobile viewport evidence was captured; mobile overflow check skipped." : "No applicable viewport evidence was captured for overflow check."
|
|
3557
|
-
};
|
|
3558
|
-
}
|
|
3559
|
-
const failed = applicable.filter((viewport) => horizontalBoundsOverflowPx(viewport) > maxOverflow);
|
|
3560
|
-
return {
|
|
3561
|
-
type: check.type,
|
|
3562
|
-
label: checkLabel(check),
|
|
3563
|
-
status: failed.length ? "failed" : "passed",
|
|
3564
|
-
evidence: {
|
|
3565
|
-
max_overflow_px: maxOverflow,
|
|
3566
|
-
overflow_px: applicable.map((viewport) => viewport.overflow_px ?? null),
|
|
3567
|
-
bounds_overflow_px: applicable.map((viewport) => horizontalBoundsOverflowPx(viewport)),
|
|
3568
|
-
overflow_offender_counts: applicable.map((viewport) => boundsOffendersForEvidence(viewport).length),
|
|
3569
|
-
viewports: applicable.map((viewport) => viewport.name)
|
|
3570
|
-
},
|
|
3571
|
-
message: failed.length ? `Horizontal bounds overflow exceeded ${maxOverflow}px in ${failed.length} viewport(s).` : void 0
|
|
3572
|
-
};
|
|
3573
|
-
}
|
|
3574
|
-
if (check.type === "no_fatal_console_errors") {
|
|
3575
|
-
const fatalConsoleEvents = (evidence.console?.events || []).filter((event) => event.type === "error" || event.type === "assert");
|
|
3576
|
-
const explicitlyAllowedConsoleEvents = fatalConsoleEvents.filter((event) => matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns));
|
|
3577
|
-
const expectedNetworkMockConsoleEvents = fatalConsoleEvents.filter((event) => !matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns) && isExpectedFailedNetworkMockConsoleEvent(event, evidence));
|
|
3578
|
-
const allowedConsoleEvents = fatalConsoleEvents.filter((event) => matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns) || isExpectedFailedNetworkMockConsoleEvent(event, evidence));
|
|
3579
|
-
const unallowedConsoleEvents = fatalConsoleEvents.filter((event) => !matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns) && !isExpectedFailedNetworkMockConsoleEvent(event, evidence));
|
|
3580
|
-
const pageErrors = evidence.page_errors || [];
|
|
3581
|
-
const allowedPageErrors = pageErrors.filter((error) => matchesAllowedMessage(error, check.allowed_page_error_texts, check.allowed_page_error_patterns));
|
|
3582
|
-
const unallowedPageErrors = pageErrors.filter((error) => !matchesAllowedMessage(error, check.allowed_page_error_texts, check.allowed_page_error_patterns));
|
|
3583
|
-
const fatalCount = unallowedConsoleEvents.length + unallowedPageErrors.length;
|
|
3584
|
-
return {
|
|
3585
|
-
type: check.type,
|
|
3586
|
-
label: checkLabel(check),
|
|
3587
|
-
status: fatalCount ? "failed" : "passed",
|
|
3588
|
-
evidence: {
|
|
3589
|
-
console_fatal_count: unallowedConsoleEvents.length,
|
|
3590
|
-
page_error_count: unallowedPageErrors.length,
|
|
3591
|
-
total_console_fatal_count: fatalConsoleEvents.length,
|
|
3592
|
-
total_page_error_count: pageErrors.length,
|
|
3593
|
-
allowed_console_fatal_count: allowedConsoleEvents.length,
|
|
3594
|
-
explicitly_allowed_console_fatal_count: explicitlyAllowedConsoleEvents.length,
|
|
3595
|
-
allowed_expected_network_mock_console_count: expectedNetworkMockConsoleEvents.length,
|
|
3596
|
-
allowed_expected_network_mock_console_events: expectedNetworkMockConsoleEvents.slice(0, 5).map((event) => expectedFailedNetworkMockConsoleEventSummary(event, evidence)),
|
|
3597
|
-
allowed_page_error_count: allowedPageErrors.length,
|
|
3598
|
-
allowed_console_texts: check.allowed_console_texts || [],
|
|
3599
|
-
allowed_console_patterns: check.allowed_console_patterns || [],
|
|
3600
|
-
allowed_page_error_texts: check.allowed_page_error_texts || [],
|
|
3601
|
-
allowed_page_error_patterns: check.allowed_page_error_patterns || []
|
|
3602
|
-
},
|
|
3603
|
-
message: fatalCount ? `${fatalCount} fatal browser error(s) were captured.` : void 0
|
|
3604
|
-
};
|
|
3605
|
-
}
|
|
3606
|
-
if (check.type === "no_console_warnings") {
|
|
3607
|
-
const warningConsoleEvents = (evidence.console?.events || []).filter((event) => event.type === "warning" || event.type === "warn");
|
|
3608
|
-
const allowedConsoleEvents = warningConsoleEvents.filter((event) => matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns));
|
|
3609
|
-
const unallowedConsoleEvents = warningConsoleEvents.filter((event) => !matchesAllowedMessage(event, check.allowed_console_texts, check.allowed_console_patterns));
|
|
3610
|
-
return {
|
|
3611
|
-
type: check.type,
|
|
3612
|
-
label: checkLabel(check),
|
|
3613
|
-
status: unallowedConsoleEvents.length ? "failed" : "passed",
|
|
3614
|
-
evidence: {
|
|
3615
|
-
console_warning_count: unallowedConsoleEvents.length,
|
|
3616
|
-
total_console_warning_count: warningConsoleEvents.length,
|
|
3617
|
-
allowed_console_warning_count: allowedConsoleEvents.length,
|
|
3618
|
-
allowed_console_texts: check.allowed_console_texts || [],
|
|
3619
|
-
allowed_console_patterns: check.allowed_console_patterns || [],
|
|
3620
|
-
unallowed_console_warning_samples: unallowedConsoleEvents.slice(0, 5).map((event) => allowedMessageSample(event)),
|
|
3621
|
-
allowed_console_warning_samples: allowedConsoleEvents.slice(0, 5).map((event) => allowedMessageSample(event))
|
|
3622
|
-
},
|
|
3623
|
-
message: unallowedConsoleEvents.length ? `${unallowedConsoleEvents.length} console warning(s) were captured.` : void 0
|
|
3624
|
-
};
|
|
3625
|
-
}
|
|
3626
|
-
return {
|
|
3627
|
-
type: check.type,
|
|
3628
|
-
label: checkLabel(check),
|
|
3629
|
-
status: "needs_human_review",
|
|
3630
|
-
evidence: {},
|
|
3631
|
-
message: "Unsupported check type."
|
|
3632
|
-
};
|
|
3633
|
-
}
|
|
3634
|
-
function assessSetupActionsFromEvidence(profile, evidence) {
|
|
3635
|
-
if (!profile.target.setup_actions?.length) return void 0;
|
|
3636
|
-
const actionCount = profile.target.setup_actions.length;
|
|
3637
|
-
const failed = [];
|
|
3638
|
-
const viewports = evidence.viewports || [];
|
|
3639
|
-
const expectedActionCountByViewport = /* @__PURE__ */ new Map();
|
|
3640
|
-
for (const viewport of viewports) {
|
|
3641
|
-
const expectedActionCount = setupActionsForViewport(profile.target.setup_actions, viewport.name).length;
|
|
3642
|
-
expectedActionCountByViewport.set(viewport.name, expectedActionCount);
|
|
3643
|
-
const results = viewport.setup_action_results || [];
|
|
3644
|
-
for (const result of results) {
|
|
3645
|
-
if (result.ok === false && result.optional !== true) {
|
|
3646
|
-
failed.push({
|
|
3647
|
-
viewport: viewport.name,
|
|
3648
|
-
action: result.action ?? result.type ?? null,
|
|
3649
|
-
selector: result.selector ?? null,
|
|
3650
|
-
frame_selector: result.frame_selector ?? null,
|
|
3651
|
-
frame_index: result.frame_index ?? null,
|
|
3652
|
-
reason: result.reason ?? result.error ?? null
|
|
3653
|
-
});
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
if (results.length < expectedActionCount && results.every((result) => result.ok !== false || result.optional === true)) {
|
|
3657
|
-
failed.push({
|
|
3658
|
-
viewport: viewport.name,
|
|
3659
|
-
action: "setup_actions",
|
|
3660
|
-
selector: null,
|
|
3661
|
-
reason: `missing setup action results: ${results.length}/${expectedActionCount}`
|
|
3662
|
-
});
|
|
3663
|
-
}
|
|
3664
|
-
}
|
|
3665
|
-
return {
|
|
3666
|
-
type: "setup_actions_succeeded",
|
|
3667
|
-
label: "setup actions succeeded",
|
|
3668
|
-
status: failed.length ? "failed" : "passed",
|
|
3669
|
-
evidence: {
|
|
3670
|
-
action_count: actionCount,
|
|
3671
|
-
viewports: viewports.map((viewport) => ({
|
|
3672
|
-
name: viewport.name,
|
|
3673
|
-
expected_action_count: expectedActionCountByViewport.get(viewport.name) ?? actionCount,
|
|
3674
|
-
ok: (viewport.setup_action_results || []).length >= (expectedActionCountByViewport.get(viewport.name) ?? actionCount) && (viewport.setup_action_results || []).every((result) => result.ok !== false || result.optional === true),
|
|
3675
|
-
result_count: (viewport.setup_action_results || []).length
|
|
3676
|
-
})),
|
|
3677
|
-
setup_summary: profileSetupSummary(viewports, actionCount, expectedActionCountByViewport, profile.target.screenshot_full_page),
|
|
3678
|
-
failed
|
|
3679
|
-
},
|
|
3680
|
-
message: failed.length ? `Setup actions failed in ${failed.length} viewport action(s).` : void 0
|
|
3681
|
-
};
|
|
3682
|
-
}
|
|
3683
|
-
function assessNetworkMocksFromEvidence(profile, evidence) {
|
|
3684
|
-
const mocks = profile.target.network_mocks || [];
|
|
3685
|
-
if (!mocks.length) return void 0;
|
|
3686
|
-
const events = evidence.network_mocks || [];
|
|
3687
|
-
const failed = [];
|
|
3688
|
-
const requiredMocks = mocks.filter((mock) => mock.required !== false);
|
|
3689
|
-
const hitCountForMock = (mock) => events.filter((event) => event.label === mock.label && event.ok !== false).length;
|
|
3690
|
-
for (const mock of requiredMocks) {
|
|
3691
|
-
const hits = hitCountForMock(mock);
|
|
3692
|
-
const requiredHitCount = requiredNetworkMockHitCount(mock);
|
|
3693
|
-
if (hits < requiredHitCount) {
|
|
3694
|
-
failed.push({
|
|
3695
|
-
label: mock.label,
|
|
3696
|
-
url: mock.url,
|
|
3697
|
-
method: mock.method || null,
|
|
3698
|
-
reason: hits < 1 ? "required_mock_not_hit" : "required_mock_hit_count_not_met",
|
|
3699
|
-
required_hit_count: requiredHitCount,
|
|
3700
|
-
hit_count: hits
|
|
3701
|
-
});
|
|
3702
|
-
}
|
|
3703
347
|
}
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
348
|
+
return result.body_json_assertions.filter((assertion) => isRecord(assertion) && assertion.ok !== true).map((assertion) => ({
|
|
349
|
+
label: stringValue(assertion.label) || stringValue(assertion.path) || "json assertion",
|
|
350
|
+
path: stringValue(assertion.path) || "",
|
|
351
|
+
ok: false,
|
|
352
|
+
exists: assertion.exists === true,
|
|
353
|
+
observed: hasOwn(assertion, "observed") ? toJsonValue(assertion.observed) : void 0,
|
|
354
|
+
observed_sample: hasOwn(assertion, "observed_sample") ? toJsonValue(assertion.observed_sample) : void 0,
|
|
355
|
+
observed_length: numberValue(assertion.observed_length),
|
|
356
|
+
observed_key_count: numberValue(assertion.observed_key_count),
|
|
357
|
+
observed_omitted_count: numberValue(assertion.observed_omitted_count),
|
|
358
|
+
observed_type: stringValue(assertion.observed_type) || "missing",
|
|
359
|
+
expected_exists: booleanValue(assertion.expected_exists),
|
|
360
|
+
equals: hasOwn(assertion, "equals") ? toJsonValue(assertion.equals) : void 0,
|
|
361
|
+
not_equals: hasOwn(assertion, "not_equals") ? toJsonValue(assertion.not_equals) : void 0,
|
|
362
|
+
contains: hasOwn(assertion, "contains") ? toJsonValue(assertion.contains) : void 0,
|
|
363
|
+
type: stringValue(assertion.type),
|
|
364
|
+
errors: Array.isArray(assertion.errors) ? assertion.errors.map(String) : void 0
|
|
365
|
+
}));
|
|
366
|
+
}
|
|
367
|
+
function linkStatusResultOk(result, check) {
|
|
368
|
+
const status = numberValue(result.status);
|
|
369
|
+
if (!httpStatusIsAllowed(status, check)) return false;
|
|
370
|
+
if (stringValue(result.error)) return false;
|
|
371
|
+
if (result.ok === false) return false;
|
|
372
|
+
if (!linkStatusContentTypeOk(result, check)) return false;
|
|
373
|
+
if (check.require_nonzero_bytes) {
|
|
374
|
+
const observedBytes = linkStatusObservedBytes(result);
|
|
375
|
+
if (observedBytes === void 0 || observedBytes <= 0) return false;
|
|
3717
376
|
}
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
label: event.label ?? null,
|
|
3722
|
-
url: event.url ?? null,
|
|
3723
|
-
method: event.method ?? null,
|
|
3724
|
-
reason: event.reason ?? event.error ?? "mock_failed"
|
|
3725
|
-
});
|
|
3726
|
-
}
|
|
3727
|
-
if (event.request_body_matches === false) {
|
|
3728
|
-
failed.push({
|
|
3729
|
-
label: event.label ?? null,
|
|
3730
|
-
response_label: event.response_label ?? null,
|
|
3731
|
-
hit_index: event.hit_index ?? null,
|
|
3732
|
-
response_index: event.response_index ?? null,
|
|
3733
|
-
url: event.url ?? null,
|
|
3734
|
-
method: event.method ?? null,
|
|
3735
|
-
reason: "request_body_mismatch",
|
|
3736
|
-
request_body_failures: event.request_body_failures ?? [],
|
|
3737
|
-
request_body_length: event.request_body_length ?? null,
|
|
3738
|
-
request_body_sample: event.request_body_sample ?? null
|
|
3739
|
-
});
|
|
3740
|
-
}
|
|
377
|
+
if (check.min_bytes !== void 0) {
|
|
378
|
+
const observedBytes = linkStatusObservedBytes(result);
|
|
379
|
+
if (observedBytes === void 0 || observedBytes < check.min_bytes) return false;
|
|
3741
380
|
}
|
|
3742
|
-
return
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
mock_count: mocks.length,
|
|
3748
|
-
required_count: requiredMocks.length,
|
|
3749
|
-
hit_count: events.filter((event) => event.ok !== false).length,
|
|
3750
|
-
hits_by_label: Object.fromEntries(mocks.map((mock) => [
|
|
3751
|
-
mock.label,
|
|
3752
|
-
hitCountForMock(mock)
|
|
3753
|
-
])),
|
|
3754
|
-
required_hits_by_label: Object.fromEntries(requiredMocks.map((mock) => [
|
|
3755
|
-
mock.label,
|
|
3756
|
-
requiredNetworkMockHitCount(mock)
|
|
3757
|
-
])),
|
|
3758
|
-
max_hits_by_label: Object.fromEntries(mocks.filter((mock) => mock.max_hit_count !== void 0).map((mock) => [mock.label, mock.max_hit_count ?? null])),
|
|
3759
|
-
response_hits_by_label: networkMockResponseHitsByLabel(events),
|
|
3760
|
-
failed
|
|
3761
|
-
},
|
|
3762
|
-
message: failed.length ? `Network mocks failed or hit-count contracts failed for ${failed.length} mock(s).` : void 0
|
|
3763
|
-
};
|
|
381
|
+
if (httpStatusBodyContainsFailures(result, check).length) return false;
|
|
382
|
+
if (httpStatusBodyNotContainsFailures(result, check).length) return false;
|
|
383
|
+
if (httpStatusBodyNotPatternFailures(result, check).length) return false;
|
|
384
|
+
if (httpStatusBodyJsonAssertionFailures(result, check).length) return false;
|
|
385
|
+
return true;
|
|
3764
386
|
}
|
|
3765
|
-
function
|
|
3766
|
-
const
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
const label = typeof event.label === "string" ? event.label : "";
|
|
3770
|
-
const responseLabel2 = typeof event.response_label === "string" ? event.response_label : "";
|
|
3771
|
-
const hasSequenceResponse = typeof event.response_index === "number" || event.sequence_cycle === true || Boolean(responseLabel2 && responseLabel2 !== label);
|
|
3772
|
-
if (!label || !responseLabel2 || !hasSequenceResponse) continue;
|
|
3773
|
-
responseHits[label] || (responseHits[label] = {});
|
|
3774
|
-
responseHits[label][responseLabel2] = (responseHits[label][responseLabel2] || 0) + 1;
|
|
3775
|
-
}
|
|
3776
|
-
return responseHits;
|
|
387
|
+
function responseHeader(response, name) {
|
|
388
|
+
const getter = response.headers?.get;
|
|
389
|
+
if (typeof getter !== "function") return null;
|
|
390
|
+
return getter.call(response.headers, name);
|
|
3777
391
|
}
|
|
3778
|
-
function
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
if (Array.isArray(mock.responses) && mock.responses.length) return mock.responses.length;
|
|
3782
|
-
return 1;
|
|
392
|
+
function responseContentLength(response) {
|
|
393
|
+
const value = responseHeader(response, "content-length");
|
|
394
|
+
return value && /^\d+$/.test(value) ? Number(value) : null;
|
|
3783
395
|
}
|
|
3784
|
-
function
|
|
3785
|
-
if (
|
|
3786
|
-
|
|
3787
|
-
const expectedViewportCount = profile.target.viewports?.length || 0;
|
|
3788
|
-
if (!viewports.length || !checks.length) return "proof_insufficient";
|
|
3789
|
-
if (viewports.some((viewport) => viewport.navigation_error)) return "environment_blocked";
|
|
3790
|
-
if (expectedViewportCount && viewports.length < expectedViewportCount) return "proof_insufficient";
|
|
3791
|
-
if (checks.some((check) => check.status === "proof_insufficient")) return "proof_insufficient";
|
|
3792
|
-
if (checks.some((check) => check.status === "needs_human_review")) return "needs_human_review";
|
|
3793
|
-
if (checks.some((check) => check.status === "failed")) return "product_regression";
|
|
3794
|
-
return "passed";
|
|
3795
|
-
}
|
|
3796
|
-
var RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS = [
|
|
3797
|
-
"screenshot",
|
|
3798
|
-
"console",
|
|
3799
|
-
"dom_summary",
|
|
3800
|
-
"proof_json"
|
|
3801
|
-
];
|
|
3802
|
-
function preflightRiddleProofProfileRunnerArtifacts(profile, runner) {
|
|
3803
|
-
const requested = uniqueNonEmptyStrings(profile.artifacts || []);
|
|
3804
|
-
if (runner !== "riddle") {
|
|
396
|
+
async function responseBodyText(response) {
|
|
397
|
+
if (typeof response.arrayBuffer === "function") {
|
|
398
|
+
const buffer = await response.arrayBuffer();
|
|
3805
399
|
return {
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
requested,
|
|
3809
|
-
local_only: [],
|
|
3810
|
-
hosted_artifacts: [...RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS]
|
|
400
|
+
text: new TextDecoder().decode(buffer),
|
|
401
|
+
bytes: buffer.byteLength
|
|
3811
402
|
};
|
|
3812
403
|
}
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
const message = localOnly.length ? `${subject} ${localOnly.length === 1 ? "is" : "are"} local-runner output; hosted runs produce proof_json, console, dom_summary, and screenshots. Remove ${localOnly.length === 1 ? "it" : "them"} from profile.artifacts for --runner riddle.` : void 0;
|
|
3816
|
-
return {
|
|
3817
|
-
ok: localOnly.length === 0,
|
|
3818
|
-
runner,
|
|
3819
|
-
requested,
|
|
3820
|
-
local_only: localOnly,
|
|
3821
|
-
hosted_artifacts: [...RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS],
|
|
3822
|
-
message
|
|
3823
|
-
};
|
|
3824
|
-
}
|
|
3825
|
-
function assessRiddleProofProfileArtifactCompleteness(profile, result, artifacts) {
|
|
3826
|
-
const required = profileRequiredArtifactKeys(profile, result);
|
|
3827
|
-
const missing = required.filter((key) => !profileArtifactKeyPresent(key, artifacts));
|
|
3828
|
-
return {
|
|
3829
|
-
ok: missing.length === 0,
|
|
3830
|
-
required,
|
|
3831
|
-
observed: artifacts.map((artifact) => profileArtifactObservedLabel(artifact)).filter(Boolean),
|
|
3832
|
-
missing
|
|
3833
|
-
};
|
|
3834
|
-
}
|
|
3835
|
-
function applyRiddleProofProfileArtifactCompleteness(profile, result, artifacts) {
|
|
3836
|
-
if (artifacts === void 0) return result;
|
|
3837
|
-
const completeness = assessRiddleProofProfileArtifactCompleteness(profile, result, artifacts);
|
|
3838
|
-
if (result.status !== "passed" || completeness.ok) {
|
|
404
|
+
if (typeof response.text === "function") {
|
|
405
|
+
const text = await response.text();
|
|
3839
406
|
return {
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
...result.artifacts,
|
|
3843
|
-
riddle_artifacts: artifacts
|
|
3844
|
-
}
|
|
407
|
+
text,
|
|
408
|
+
bytes: new TextEncoder().encode(text).byteLength
|
|
3845
409
|
};
|
|
3846
410
|
}
|
|
3847
|
-
|
|
3848
|
-
const message = `Missing required profile artifact(s): ${missing}`;
|
|
3849
|
-
const warnings = [...result.warnings || [], message];
|
|
3850
|
-
return {
|
|
3851
|
-
...result,
|
|
3852
|
-
status: "proof_insufficient",
|
|
3853
|
-
artifacts: {
|
|
3854
|
-
...result.artifacts,
|
|
3855
|
-
riddle_artifacts: artifacts
|
|
3856
|
-
},
|
|
3857
|
-
summary: `${profile.name} did not produce required profile artifact(s): ${missing}.`,
|
|
3858
|
-
warnings,
|
|
3859
|
-
error: message
|
|
3860
|
-
};
|
|
411
|
+
return { text: "", bytes: null };
|
|
3861
412
|
}
|
|
3862
|
-
function
|
|
3863
|
-
const
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
if (role === "screenshot") {
|
|
3868
|
-
const screenshots = result.artifacts.screenshots || [];
|
|
3869
|
-
if (screenshots.length) {
|
|
3870
|
-
keys.push(...screenshots.map((label) => `screenshot:${label}`));
|
|
3871
|
-
} else {
|
|
3872
|
-
keys.push("screenshot");
|
|
3873
|
-
}
|
|
3874
|
-
continue;
|
|
413
|
+
function httpStatusRequestBody(check) {
|
|
414
|
+
const headers = isRecord(check.headers) ? Object.fromEntries(Object.entries(check.headers).map(([key, value]) => [key, String(value)]).filter(([key]) => key.trim())) : {};
|
|
415
|
+
if (check.body_json !== void 0) {
|
|
416
|
+
if (!Object.keys(headers).some((key) => key.toLowerCase() === "content-type")) {
|
|
417
|
+
headers["content-type"] = "application/json";
|
|
3875
418
|
}
|
|
3876
|
-
|
|
3877
|
-
}
|
|
3878
|
-
return uniqueNonEmptyStrings(keys);
|
|
3879
|
-
}
|
|
3880
|
-
function normalizeProfileArtifactRole(input) {
|
|
3881
|
-
const normalized = input.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
3882
|
-
if (!normalized) return "";
|
|
3883
|
-
if (normalized === "screenshots") return "screenshot";
|
|
3884
|
-
if (normalized === "console" || normalized === "console_json" || normalized === "console.json") return "console.json";
|
|
3885
|
-
if (normalized === "dom_summary" || normalized === "dom_summary_json" || normalized === "dom-summary.json") return "dom-summary.json";
|
|
3886
|
-
if (normalized === "proof" || normalized === "proof_json" || normalized === "proof.json") return "proof.json";
|
|
3887
|
-
return normalizeRiddleProfileArtifactName(input.trim()).toLowerCase();
|
|
3888
|
-
}
|
|
3889
|
-
function profileArtifactIsHostedLocalOnly(input) {
|
|
3890
|
-
const raw = input.trim().toLowerCase();
|
|
3891
|
-
const normalized = raw.replace(/[\s-]+/g, "_");
|
|
3892
|
-
const role = normalizeProfileArtifactRole(input);
|
|
3893
|
-
return [
|
|
3894
|
-
raw,
|
|
3895
|
-
normalized,
|
|
3896
|
-
role
|
|
3897
|
-
].some((value) => value === "artifact_manifest" || value === "artifact_manifest.json" || value === "artifact-manifest" || value === "artifact-manifest.json");
|
|
3898
|
-
}
|
|
3899
|
-
function profileArtifactKeyPresent(key, artifacts) {
|
|
3900
|
-
if (key.startsWith("screenshot:")) {
|
|
3901
|
-
const label = key.slice("screenshot:".length);
|
|
3902
|
-
return artifacts.some((artifact) => profileArtifactRefIsScreenshot(artifact) && profileArtifactRefText(artifact).includes(label.toLowerCase()));
|
|
3903
|
-
}
|
|
3904
|
-
if (key === "screenshot") {
|
|
3905
|
-
return artifacts.some((artifact) => profileArtifactRefIsScreenshot(artifact));
|
|
3906
|
-
}
|
|
3907
|
-
return artifacts.some((artifact) => {
|
|
3908
|
-
const name = normalizeRiddleProfileArtifactName(artifact.name || artifactNameFromPath(artifact.url || artifact.path) || "").toLowerCase();
|
|
3909
|
-
return name === key || profileArtifactRefText(artifact).includes(key);
|
|
3910
|
-
});
|
|
3911
|
-
}
|
|
3912
|
-
function profileArtifactRefIsScreenshot(artifact) {
|
|
3913
|
-
const kind = (artifact.kind || "").toLowerCase();
|
|
3914
|
-
const contentType = (artifact.content_type || "").toLowerCase();
|
|
3915
|
-
const text = profileArtifactRefText(artifact);
|
|
3916
|
-
return kind === "screenshot" || contentType.startsWith("image/") || /\.(png|jpe?g|webp)(?:$|[?#])/i.test(text) || /\.(png|jpe?g|webp)$/i.test(text);
|
|
3917
|
-
}
|
|
3918
|
-
function profileArtifactRefText(artifact) {
|
|
3919
|
-
return [
|
|
3920
|
-
artifact.name,
|
|
3921
|
-
artifact.url,
|
|
3922
|
-
artifact.path,
|
|
3923
|
-
artifact.kind,
|
|
3924
|
-
artifact.content_type
|
|
3925
|
-
].filter(Boolean).join(" ").toLowerCase();
|
|
3926
|
-
}
|
|
3927
|
-
function profileArtifactObservedLabel(artifact) {
|
|
3928
|
-
return artifact.name || artifact.url || artifact.path || artifact.kind || "";
|
|
3929
|
-
}
|
|
3930
|
-
function assessRiddleProofProfileEvidence(profile, evidence, options = {}) {
|
|
3931
|
-
const capturedAt = evidence?.captured_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
3932
|
-
const warnings = collectRiddleProofProfileWarnings(profile);
|
|
3933
|
-
const checks = evidence ? [
|
|
3934
|
-
assessNetworkMocksFromEvidence(profile, evidence),
|
|
3935
|
-
assessSetupActionsFromEvidence(profile, evidence),
|
|
3936
|
-
...profile.checks.map((check) => assessCheckFromEvidence(check, evidence))
|
|
3937
|
-
].filter((check) => Boolean(check)) : [];
|
|
3938
|
-
const status = profileStatusFromEvidence(profile, evidence, checks);
|
|
3939
|
-
const firstViewport = evidence?.viewports?.[0];
|
|
3940
|
-
const screenshots = profileScreenshotLabels(evidence?.viewports);
|
|
3941
|
-
const canonicalScreenshots = profileFinalScreenshotLabels(evidence?.viewports);
|
|
3942
|
-
const setupScreenshots = profileAllSetupScreenshotLabels(evidence?.viewports);
|
|
3943
|
-
const result = {
|
|
3944
|
-
version: RIDDLE_PROOF_PROFILE_RESULT_VERSION,
|
|
3945
|
-
profile_name: profile.name,
|
|
3946
|
-
runner: options.runner || "riddle",
|
|
3947
|
-
status,
|
|
3948
|
-
baseline_policy: profile.baseline_policy,
|
|
3949
|
-
route: routeForViewport(firstViewport, evidence?.target_url),
|
|
3950
|
-
artifacts: {
|
|
3951
|
-
screenshots,
|
|
3952
|
-
canonical_screenshots: canonicalScreenshots,
|
|
3953
|
-
setup_screenshots: setupScreenshots,
|
|
3954
|
-
console: "console.json",
|
|
3955
|
-
proof_json: "proof.json",
|
|
3956
|
-
dom_summary: "dom-summary.json",
|
|
3957
|
-
riddle_artifacts: options.artifacts
|
|
3958
|
-
},
|
|
3959
|
-
checks,
|
|
3960
|
-
summary: summarizeRiddleProofProfileResult({ profile_name: profile.name, status, checks, viewports: evidence?.viewports || [] }),
|
|
3961
|
-
captured_at: capturedAt,
|
|
3962
|
-
metadata: profile.metadata,
|
|
3963
|
-
warnings: warnings.length ? warnings : void 0,
|
|
3964
|
-
evidence,
|
|
3965
|
-
riddle: options.riddle
|
|
3966
|
-
};
|
|
3967
|
-
return applyRiddleProofProfileArtifactCompleteness(profile, result, options.artifacts);
|
|
3968
|
-
}
|
|
3969
|
-
function summarizeRiddleProofProfileResult(input) {
|
|
3970
|
-
const passedChecks = input.checks.filter((check) => check.status === "passed").length;
|
|
3971
|
-
const failedChecks = input.checks.filter((check) => check.status === "failed").length;
|
|
3972
|
-
const viewportNames = input.viewports.map((viewport) => viewport.name).join(", ");
|
|
3973
|
-
if (input.status === "passed") {
|
|
3974
|
-
return `${input.profile_name} passed ${passedChecks} check(s) across ${input.viewports.length} viewport(s)${viewportNames ? ` (${viewportNames})` : ""}.`;
|
|
3975
|
-
}
|
|
3976
|
-
if (input.status === "product_regression") {
|
|
3977
|
-
return `${input.profile_name} failed ${failedChecks} product invariant(s) across ${input.viewports.length} viewport(s).`;
|
|
3978
|
-
}
|
|
3979
|
-
if (input.status === "environment_blocked") {
|
|
3980
|
-
return `${input.profile_name} could not collect reliable evidence because navigation or the browser environment was blocked.`;
|
|
3981
|
-
}
|
|
3982
|
-
if (input.status === "proof_insufficient") {
|
|
3983
|
-
return `${input.profile_name} did not produce enough evidence for a profile judgment.`;
|
|
3984
|
-
}
|
|
3985
|
-
if (input.status === "configuration_error") {
|
|
3986
|
-
return `${input.profile_name} has a profile configuration error.`;
|
|
419
|
+
return { headers, body: JSON.stringify(check.body_json) };
|
|
3987
420
|
}
|
|
3988
|
-
|
|
3989
|
-
}
|
|
3990
|
-
function profileStatusExitCode(profile, status) {
|
|
3991
|
-
if (status === "passed") return 0;
|
|
3992
|
-
return profile.failure_policy[status] === "neutral" ? 0 : 1;
|
|
3993
|
-
}
|
|
3994
|
-
function createRiddleProofProfileConfigurationError(profileOrName, error, runner = "riddle", options = {}) {
|
|
3995
|
-
const profile = typeof profileOrName === "string" ? void 0 : profileOrName;
|
|
3996
|
-
const name = profile ? profile.name : String(profileOrName);
|
|
3997
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
3998
|
-
let requested = "";
|
|
3999
|
-
if (profile) {
|
|
4000
|
-
try {
|
|
4001
|
-
requested = resolveRiddleProofProfileTargetUrl(profile);
|
|
4002
|
-
} catch {
|
|
4003
|
-
requested = "";
|
|
4004
|
-
}
|
|
421
|
+
if (typeof check.body === "string") {
|
|
422
|
+
return { headers, body: check.body };
|
|
4005
423
|
}
|
|
4006
|
-
return {
|
|
4007
|
-
version: RIDDLE_PROOF_PROFILE_RESULT_VERSION,
|
|
4008
|
-
profile_name: name,
|
|
4009
|
-
runner,
|
|
4010
|
-
status: "configuration_error",
|
|
4011
|
-
baseline_policy: profile?.baseline_policy || "invariant_only",
|
|
4012
|
-
route: { requested, observed: "", matched: false, error: message },
|
|
4013
|
-
artifacts: { screenshots: [], proof_json: "proof.json" },
|
|
4014
|
-
checks: [],
|
|
4015
|
-
summary: `${name} has a profile configuration error.`,
|
|
4016
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4017
|
-
metadata: profile?.metadata,
|
|
4018
|
-
warnings: options.warnings?.length ? options.warnings : void 0,
|
|
4019
|
-
configuration_blocker: options.configurationBlocker,
|
|
4020
|
-
error: message
|
|
4021
|
-
};
|
|
424
|
+
return { headers };
|
|
4022
425
|
}
|
|
4023
|
-
function
|
|
4024
|
-
const
|
|
4025
|
-
const
|
|
4026
|
-
const
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
baseline_policy: input.profile.baseline_policy,
|
|
4033
|
-
route: { requested: resolveRiddleProofProfileTargetUrl(input.profile), observed: "", matched: false, error: message },
|
|
4034
|
-
artifacts: { screenshots: [], proof_json: "proof.json", riddle_artifacts: input.artifacts },
|
|
4035
|
-
checks: [],
|
|
4036
|
-
summary: summarizeEnvironmentBlockedRunner(input.profile.name, environmentBlocker),
|
|
4037
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4038
|
-
metadata: input.profile.metadata,
|
|
4039
|
-
warnings: warnings.length ? warnings : void 0,
|
|
4040
|
-
riddle: input.riddle,
|
|
4041
|
-
environment_blocker: environmentBlocker,
|
|
4042
|
-
error: message
|
|
426
|
+
async function preflightHttpStatusCheck(check, index, targetUrl, fetchImpl) {
|
|
427
|
+
const url = httpStatusRequestUrl(check, targetUrl);
|
|
428
|
+
const method = httpStatusMethod(check);
|
|
429
|
+
const request = httpStatusRequestBody(check);
|
|
430
|
+
const init = {
|
|
431
|
+
method,
|
|
432
|
+
redirect: "follow",
|
|
433
|
+
cache: "no-store",
|
|
434
|
+
headers: request.headers
|
|
4043
435
|
};
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
436
|
+
if (request.body !== void 0 && method !== "GET" && method !== "HEAD") {
|
|
437
|
+
init.body = request.body;
|
|
438
|
+
}
|
|
439
|
+
const result = {
|
|
440
|
+
status: null,
|
|
441
|
+
content_type: null,
|
|
442
|
+
content_length: null,
|
|
443
|
+
bytes: null
|
|
4052
444
|
};
|
|
4053
|
-
let
|
|
445
|
+
let error = null;
|
|
446
|
+
let statusText = "";
|
|
4054
447
|
try {
|
|
4055
|
-
const
|
|
4056
|
-
|
|
4057
|
-
|
|
448
|
+
const response = await fetchImpl(url, init);
|
|
449
|
+
result.status = typeof response.status === "number" && Number.isFinite(response.status) ? response.status : null;
|
|
450
|
+
statusText = typeof response.statusText === "string" ? response.statusText : "";
|
|
451
|
+
result.content_type = responseHeader(response, "content-type");
|
|
452
|
+
result.content_length = responseContentLength(response);
|
|
453
|
+
const shouldReadBody = check.require_nonzero_bytes === true || typeof check.min_bytes === "number" || Boolean(check.body_contains?.length) || Boolean(check.body_not_contains?.length) || Boolean(check.body_not_patterns?.length) || Boolean(check.body_json_assertions?.length);
|
|
454
|
+
if (shouldReadBody && method !== "HEAD") {
|
|
455
|
+
const body = await responseBodyText(response);
|
|
456
|
+
result.bytes = body.bytes;
|
|
457
|
+
if (check.body_contains?.length) {
|
|
458
|
+
result.body_contains = Object.fromEntries(check.body_contains.filter(Boolean).map((snippet) => [snippet, body.text.includes(snippet)]));
|
|
459
|
+
}
|
|
460
|
+
if (check.body_not_contains?.length) {
|
|
461
|
+
result.body_not_contains = Object.fromEntries(check.body_not_contains.filter(Boolean).map((snippet) => [snippet, body.text.includes(snippet)]));
|
|
462
|
+
}
|
|
463
|
+
if (check.body_not_patterns?.length) {
|
|
464
|
+
result.body_not_patterns = Object.fromEntries(check.body_not_patterns.filter(Boolean).map((pattern) => [pattern, new RegExp(pattern).test(body.text)]));
|
|
465
|
+
}
|
|
466
|
+
if (check.body_json_assertions?.length) {
|
|
467
|
+
result.body_json_assertions = evaluateHttpStatusBodyJsonAssertions(body.text, check.body_json_assertions);
|
|
468
|
+
}
|
|
4058
469
|
}
|
|
4059
|
-
} catch {
|
|
4060
|
-
|
|
470
|
+
} catch (caught) {
|
|
471
|
+
error = String(caught instanceof Error ? caught.message : caught).slice(0, 500);
|
|
472
|
+
result.error = error;
|
|
4061
473
|
}
|
|
4062
|
-
const
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
474
|
+
const bodyContainsMissing = httpStatusBodyContainsFailures(result, check);
|
|
475
|
+
const bodyNotContainsFound = httpStatusBodyNotContainsFailures(result, check);
|
|
476
|
+
const bodyNotPatternsFound = httpStatusBodyNotPatternFailures(result, check);
|
|
477
|
+
const bodyJsonAssertionsFailed = httpStatusBodyJsonAssertionFailures(result, check);
|
|
478
|
+
const ok = !error && linkStatusResultOk(result, check);
|
|
479
|
+
return {
|
|
480
|
+
index,
|
|
481
|
+
label: checkLabel(check) || `checks[${index}]`,
|
|
482
|
+
url,
|
|
483
|
+
method,
|
|
484
|
+
ok,
|
|
485
|
+
status: numberValue(result.status) ?? null,
|
|
486
|
+
status_text: statusText,
|
|
487
|
+
error,
|
|
488
|
+
content_type: stringValue(result.content_type) ?? null,
|
|
489
|
+
content_length: numberValue(result.content_length) ?? null,
|
|
490
|
+
bytes: numberValue(result.bytes) ?? null,
|
|
491
|
+
body_contains: isRecord(result.body_contains) ? Object.fromEntries(Object.entries(result.body_contains).map(([key, value]) => [key, value === true])) : null,
|
|
492
|
+
body_contains_missing: bodyContainsMissing,
|
|
493
|
+
body_not_contains: isRecord(result.body_not_contains) ? Object.fromEntries(Object.entries(result.body_not_contains).map(([key, value]) => [key, value === true])) : null,
|
|
494
|
+
body_not_contains_found: bodyNotContainsFound,
|
|
495
|
+
body_not_patterns: isRecord(result.body_not_patterns) ? Object.fromEntries(Object.entries(result.body_not_patterns).map(([key, value]) => [key, value === true])) : null,
|
|
496
|
+
body_not_patterns_found: bodyNotPatternsFound,
|
|
497
|
+
body_json_assertions: Array.isArray(result.body_json_assertions) ? result.body_json_assertions : null,
|
|
498
|
+
body_json_assertions_failed: bodyJsonAssertionsFailed
|
|
4066
499
|
};
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
const
|
|
4071
|
-
if (
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
}
|
|
4075
|
-
const
|
|
4076
|
-
const
|
|
4077
|
-
if (httpStatus === 402 && errorText.includes("balance")) {
|
|
4078
|
-
details.reason = "insufficient_balance";
|
|
4079
|
-
}
|
|
4080
|
-
return details;
|
|
4081
|
-
}
|
|
4082
|
-
function summarizeEnvironmentBlockedRunner(profileName, blocker) {
|
|
4083
|
-
if (blocker?.reason === "insufficient_balance") {
|
|
4084
|
-
const required = typeof blocker.required_seconds === "number" ? blocker.required_seconds : void 0;
|
|
4085
|
-
const available = typeof blocker.available_seconds === "number" ? blocker.available_seconds : void 0;
|
|
4086
|
-
const deficit = typeof blocker.deficit_seconds === "number" ? blocker.deficit_seconds : void 0;
|
|
4087
|
-
const parts = [
|
|
4088
|
-
required === void 0 ? "" : `required ${required}s`,
|
|
4089
|
-
available === void 0 ? "" : `available ${available}s`,
|
|
4090
|
-
deficit === void 0 ? "" : `deficit ${deficit}s`
|
|
4091
|
-
].filter(Boolean);
|
|
4092
|
-
return `${profileName} could not start because Riddle balance was insufficient${parts.length ? ` (${parts.join(", ")})` : ""}.`;
|
|
4093
|
-
}
|
|
4094
|
-
if (blocker?.source === "riddle_api") {
|
|
4095
|
-
const endpoint = typeof blocker.endpoint === "string" ? blocker.endpoint : "Riddle API";
|
|
4096
|
-
const status = typeof blocker.http_status === "number" ? blocker.http_status : void 0;
|
|
4097
|
-
return `${profileName} could not start because ${endpoint} returned${status === void 0 ? "" : ` HTTP ${status}`}.`;
|
|
4098
|
-
}
|
|
4099
|
-
return `${profileName} could not collect reliable evidence because the runner was blocked.`;
|
|
4100
|
-
}
|
|
4101
|
-
function createRiddleProofProfileInsufficientResult(input) {
|
|
4102
|
-
const message = input.error instanceof Error ? input.error.message : input.error ? String(input.error) : "No proof.json profile result artifact was found.";
|
|
4103
|
-
const warnings = collectRiddleProofProfileWarnings(input.profile);
|
|
500
|
+
}
|
|
501
|
+
async function preflightRiddleProofProfileHttpStatusChecks(profile, options = {}) {
|
|
502
|
+
const targetUrl = options.target_url || resolveRiddleProofProfileTargetUrl(profile);
|
|
503
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
504
|
+
if (typeof fetchImpl !== "function") {
|
|
505
|
+
throw new Error("profile http_status preflight requires fetch support or options.fetchImpl.");
|
|
506
|
+
}
|
|
507
|
+
const httpStatusChecks = profile.checks.map((check, index) => ({ check, index })).filter((item) => item.check.type === "http_status");
|
|
508
|
+
const checks = await Promise.all(httpStatusChecks.map((item) => preflightHttpStatusCheck(item.check, item.index, targetUrl, fetchImpl)));
|
|
509
|
+
const failed = checks.filter((check) => !check.ok).length;
|
|
4104
510
|
return {
|
|
4105
|
-
version:
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
checks:
|
|
4113
|
-
summary: `${input.profile.name} did not produce enough evidence for a profile judgment.`,
|
|
4114
|
-
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4115
|
-
metadata: input.profile.metadata,
|
|
4116
|
-
warnings: warnings.length ? warnings : void 0,
|
|
4117
|
-
riddle: input.riddle,
|
|
4118
|
-
error: message
|
|
511
|
+
version: "riddle-proof.profile-http-status-preflight.v1",
|
|
512
|
+
ok: failed === 0,
|
|
513
|
+
profile_name: profile.name,
|
|
514
|
+
target_url: targetUrl,
|
|
515
|
+
checked: checks.length,
|
|
516
|
+
failed,
|
|
517
|
+
checks,
|
|
518
|
+
summary: failed === 0 ? `${profile.name} http_status preflight passed ${checks.length} check(s).` : `${profile.name} http_status preflight failed ${failed} of ${checks.length} check(s).`
|
|
4119
519
|
};
|
|
4120
520
|
}
|
|
521
|
+
function previewMountPrefix(pathname) {
|
|
522
|
+
const value = pathname || "/";
|
|
523
|
+
const apiPreview = value.match(/^(\/s\/[^/]+)(?:\/|$)/);
|
|
524
|
+
if (apiPreview) return apiPreview[1];
|
|
525
|
+
const internalPreview = value.match(/^(\/preview\/[^/]+\/[^/]+)(?:\/|$)/);
|
|
526
|
+
return internalPreview ? internalPreview[1] : "";
|
|
527
|
+
}
|
|
528
|
+
function joinMountedRoutePath(mountPrefix, routePath) {
|
|
529
|
+
const route = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
530
|
+
if (!mountPrefix) return route;
|
|
531
|
+
if (route === mountPrefix || route.startsWith(`${mountPrefix}/`)) return route;
|
|
532
|
+
return `${mountPrefix}${route}`;
|
|
533
|
+
}
|
|
4121
534
|
function runtimeScriptAssessmentSource(includeOrderedTrace = false) {
|
|
4122
535
|
const orderedTraceSource = includeOrderedTrace ? String.raw`
|
|
4123
536
|
const assessRiddleProofOrderedTrace = ${assessRiddleProofOrderedTrace.toString()};
|
|
@@ -9871,128 +6284,37 @@ for (const viewport of profile.target.viewports || []) {
|
|
|
9871
6284
|
return result;
|
|
9872
6285
|
`.trim();
|
|
9873
6286
|
}
|
|
9874
|
-
function collectRiddleProfileArtifactRefs(input) {
|
|
9875
|
-
const refs = [];
|
|
9876
|
-
const indexes = /* @__PURE__ */ new Map();
|
|
9877
|
-
const priorities = /* @__PURE__ */ new Map();
|
|
9878
|
-
function add(item, source) {
|
|
9879
|
-
if (!isRecord(item)) return;
|
|
9880
|
-
const url = stringValue(item.url);
|
|
9881
|
-
const path = stringValue(item.path);
|
|
9882
|
-
const rawName = stringValue(item.name) || stringValue(item.filename) || artifactNameFromPath(url || path) || "";
|
|
9883
|
-
const name = normalizeRiddleProfileArtifactName(rawName);
|
|
9884
|
-
if (!name && !url && !path) return;
|
|
9885
|
-
const key = profileArtifactDedupeKey(name, url || path || "");
|
|
9886
|
-
const priority = profileArtifactPriority(rawName, name);
|
|
9887
|
-
const ref = {
|
|
9888
|
-
name,
|
|
9889
|
-
url,
|
|
9890
|
-
path,
|
|
9891
|
-
kind: stringValue(item.kind) || stringValue(item.type),
|
|
9892
|
-
content_type: stringValue(item.content_type) || stringValue(item.contentType),
|
|
9893
|
-
source
|
|
9894
|
-
};
|
|
9895
|
-
const existingIndex = indexes.get(key);
|
|
9896
|
-
if (existingIndex !== void 0) {
|
|
9897
|
-
if (priority > (priorities.get(key) || 0)) {
|
|
9898
|
-
refs[existingIndex] = ref;
|
|
9899
|
-
priorities.set(key, priority);
|
|
9900
|
-
}
|
|
9901
|
-
return;
|
|
9902
|
-
}
|
|
9903
|
-
indexes.set(key, refs.length);
|
|
9904
|
-
priorities.set(key, priority);
|
|
9905
|
-
refs.push(ref);
|
|
9906
|
-
}
|
|
9907
|
-
function visit(value, source) {
|
|
9908
|
-
if (Array.isArray(value)) {
|
|
9909
|
-
for (const item of value) add(item, source);
|
|
9910
|
-
return;
|
|
9911
|
-
}
|
|
9912
|
-
if (!isRecord(value)) return;
|
|
9913
|
-
for (const key of ["artifacts", "outputs", "screenshots", "files"]) {
|
|
9914
|
-
if (Array.isArray(value[key])) visit(value[key], key);
|
|
9915
|
-
}
|
|
9916
|
-
}
|
|
9917
|
-
visit(input, "artifacts");
|
|
9918
|
-
return refs;
|
|
9919
|
-
}
|
|
9920
|
-
function normalizeRiddleProfileArtifactName(name) {
|
|
9921
|
-
return name.replace(/\.json\.json$/i, ".json");
|
|
9922
|
-
}
|
|
9923
|
-
function profileArtifactDedupeKey(name, location) {
|
|
9924
|
-
if (PROFILE_SINGLETON_ARTIFACT_NAMES.has(name.toLowerCase())) return name.toLowerCase();
|
|
9925
|
-
return `${name}:${location}`;
|
|
9926
|
-
}
|
|
9927
|
-
function profileArtifactPriority(rawName, normalizedName) {
|
|
9928
|
-
const lower = normalizedName.toLowerCase();
|
|
9929
|
-
if (!PROFILE_SINGLETON_ARTIFACT_NAMES.has(lower)) return 1;
|
|
9930
|
-
return /\.json\.json$/i.test(rawName) ? 2 : 1;
|
|
9931
|
-
}
|
|
9932
|
-
function artifactNameFromPath(value) {
|
|
9933
|
-
if (!value) return "";
|
|
9934
|
-
try {
|
|
9935
|
-
return new URL(value).pathname.split("/").filter(Boolean).pop() || "";
|
|
9936
|
-
} catch {
|
|
9937
|
-
return value.split(/[\\/]/).filter(Boolean).pop() || "";
|
|
9938
|
-
}
|
|
9939
|
-
}
|
|
9940
|
-
var PROFILE_SINGLETON_ARTIFACT_NAMES = /* @__PURE__ */ new Set([
|
|
9941
|
-
"proof.json",
|
|
9942
|
-
"console.json",
|
|
9943
|
-
"dom-summary.json"
|
|
9944
|
-
]);
|
|
9945
|
-
function extractRiddleProofProfileResult(input) {
|
|
9946
|
-
if (!isRecord(input)) return void 0;
|
|
9947
|
-
if (input.version === RIDDLE_PROOF_PROFILE_RESULT_VERSION) return input;
|
|
9948
|
-
const candidates = [
|
|
9949
|
-
input.result,
|
|
9950
|
-
input.return_value,
|
|
9951
|
-
input.value,
|
|
9952
|
-
input.profile_result,
|
|
9953
|
-
isRecord(input["proof.json"]) ? input["proof.json"] : void 0,
|
|
9954
|
-
isRecord(input._proof_json) ? input._proof_json : void 0
|
|
9955
|
-
];
|
|
9956
|
-
for (const candidate of candidates) {
|
|
9957
|
-
const result = extractRiddleProofProfileResult(candidate);
|
|
9958
|
-
if (result) return result;
|
|
9959
|
-
}
|
|
9960
|
-
if (isRecord(input._artifact_json)) {
|
|
9961
|
-
return extractRiddleProofProfileResult(input._artifact_json["proof.json"]);
|
|
9962
|
-
}
|
|
9963
|
-
return void 0;
|
|
9964
|
-
}
|
|
9965
6287
|
|
|
9966
6288
|
export {
|
|
9967
|
-
|
|
6289
|
+
preflightRiddleProofProfileHttpStatusChecks,
|
|
6290
|
+
buildRiddleProofProfileScript,
|
|
6291
|
+
RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS,
|
|
6292
|
+
RIDDLE_PROOF_ORDERED_TRACE_OPERATORS,
|
|
6293
|
+
RIDDLE_PROOF_PROFILE_CHECK_TYPES,
|
|
9968
6294
|
RIDDLE_PROOF_PROFILE_EVIDENCE_VERSION,
|
|
6295
|
+
RIDDLE_PROOF_PROFILE_NETWORK_ABORT_ERROR_CODES,
|
|
9969
6296
|
RIDDLE_PROOF_PROFILE_RESULT_VERSION,
|
|
9970
|
-
RIDDLE_PROOF_PROFILE_STATUSES,
|
|
9971
|
-
RIDDLE_PROOF_PROFILE_CHECK_TYPES,
|
|
9972
6297
|
RIDDLE_PROOF_PROFILE_SETUP_ACTION_TYPES,
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
deriveRiddleProofArtifactBodyAssertions,
|
|
9976
|
-
assessRiddleProofOrderedTrace,
|
|
9977
|
-
assessRiddleProofOrderedTraceSetupResults,
|
|
9978
|
-
slugifyRiddleProofProfileName,
|
|
9979
|
-
collectRiddleProofProfileWarnings,
|
|
9980
|
-
normalizeRiddleProofProfile,
|
|
9981
|
-
resolveRiddleProofProfileTargetUrl,
|
|
9982
|
-
resolveRiddleProofProfileTimeoutSec,
|
|
9983
|
-
preflightRiddleProofProfileHttpStatusChecks,
|
|
9984
|
-
resolveRiddleProofProfileRouteUrl,
|
|
9985
|
-
RIDDLE_PROOF_HOSTED_PROFILE_ARTIFACTS,
|
|
9986
|
-
preflightRiddleProofProfileRunnerArtifacts,
|
|
9987
|
-
assessRiddleProofProfileArtifactCompleteness,
|
|
6298
|
+
RIDDLE_PROOF_PROFILE_STATUSES,
|
|
6299
|
+
RIDDLE_PROOF_PROFILE_VERSION,
|
|
9988
6300
|
applyRiddleProofProfileArtifactCompleteness,
|
|
6301
|
+
assessRiddleProofOrderedTrace2 as assessRiddleProofOrderedTrace,
|
|
6302
|
+
assessRiddleProofOrderedTraceSetupResults2 as assessRiddleProofOrderedTraceSetupResults,
|
|
6303
|
+
assessRiddleProofProfileArtifactCompleteness,
|
|
9989
6304
|
assessRiddleProofProfileEvidence,
|
|
9990
|
-
|
|
9991
|
-
|
|
6305
|
+
collectRiddleProfileArtifactRefs,
|
|
6306
|
+
collectRiddleProofProfileWarnings2 as collectRiddleProofProfileWarnings,
|
|
9992
6307
|
createRiddleProofProfileConfigurationError,
|
|
9993
6308
|
createRiddleProofProfileEnvironmentBlockedResult,
|
|
9994
6309
|
createRiddleProofProfileInsufficientResult,
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
6310
|
+
deriveRiddleProofArtifactBodyAssertions,
|
|
6311
|
+
extractRiddleProofProfileResult,
|
|
6312
|
+
normalizeRiddleProofProfile,
|
|
6313
|
+
preflightRiddleProofProfileRunnerArtifacts,
|
|
6314
|
+
profileStatusExitCode,
|
|
6315
|
+
resolveRiddleProofProfileRouteUrl,
|
|
6316
|
+
resolveRiddleProofProfileTargetUrl2 as resolveRiddleProofProfileTargetUrl,
|
|
6317
|
+
resolveRiddleProofProfileTimeoutSec,
|
|
6318
|
+
slugifyRiddleProofProfileName2 as slugifyRiddleProofProfileName,
|
|
6319
|
+
summarizeRiddleProofProfileResult
|
|
9998
6320
|
};
|