@riddledc/riddle-proof 0.7.89 → 0.7.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/{chunk-CEBHV23V.js → chunk-4FMBHM4E.js} +484 -2
- package/dist/cli.cjs +515 -2
- package/dist/cli.js +32 -1
- package/dist/index.cjs +484 -2
- package/dist/index.js +1 -1
- package/dist/profile.cjs +484 -2
- package/dist/profile.d.cts +9 -1
- package/dist/profile.d.ts +9 -1
- package/dist/profile.js +1 -1
- package/dist/proof-run-core.d.cts +1 -1
- package/dist/proof-run-core.d.ts +1 -1
- package/dist/proof-run-engine.d.cts +3 -3
- package/dist/proof-run-engine.d.ts +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
profileStatusExitCode,
|
|
11
11
|
resolveRiddleProofProfileTargetUrl,
|
|
12
12
|
resolveRiddleProofProfileTimeoutSec
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-4FMBHM4E.js";
|
|
14
14
|
import {
|
|
15
15
|
createRiddleApiClient,
|
|
16
16
|
parseRiddleViewport
|
|
@@ -337,6 +337,10 @@ function profileResultMarkdown(result) {
|
|
|
337
337
|
if (routeInventorySummaryLines.length) {
|
|
338
338
|
lines.push("", "## Route Inventory", "", ...routeInventorySummaryLines);
|
|
339
339
|
}
|
|
340
|
+
const linkStatusSummaryLines = profileLinkStatusSummaryMarkdown(result);
|
|
341
|
+
if (linkStatusSummaryLines.length) {
|
|
342
|
+
lines.push("", "## Link Status", "", ...linkStatusSummaryLines);
|
|
343
|
+
}
|
|
340
344
|
const environmentBlockerLines = profileEnvironmentBlockerMarkdown(result);
|
|
341
345
|
if (environmentBlockerLines.length) {
|
|
342
346
|
lines.push("", "## Environment Blocker", "", ...environmentBlockerLines);
|
|
@@ -406,6 +410,13 @@ function profileCheckMarkdownTarget(check) {
|
|
|
406
410
|
if (selector && maxOverflow !== void 0) return `${markdownInlineCode(selector)} <= ${maxOverflow}px`;
|
|
407
411
|
return selector ? markdownInlineCode(selector) : maxOverflow !== void 0 ? `<= ${maxOverflow}px` : void 0;
|
|
408
412
|
}
|
|
413
|
+
if (check.type === "link_status" || check.type === "artifact_link_status") {
|
|
414
|
+
const expectedCount = cliFiniteNumber(evidence.expected_count);
|
|
415
|
+
const minCount = cliFiniteNumber(evidence.min_count);
|
|
416
|
+
if (selector && expectedCount !== void 0) return `${markdownInlineCode(selector)} links = ${expectedCount}`;
|
|
417
|
+
if (selector && minCount !== void 0) return `${markdownInlineCode(selector)} links >= ${minCount}`;
|
|
418
|
+
return selector ? markdownInlineCode(selector) : void 0;
|
|
419
|
+
}
|
|
409
420
|
if (check.type === "no_horizontal_overflow" || check.type === "no_mobile_horizontal_overflow") {
|
|
410
421
|
const maxOverflow = cliFiniteNumber(evidence.max_overflow_px);
|
|
411
422
|
return maxOverflow !== void 0 ? `<= ${maxOverflow}px` : void 0;
|
|
@@ -599,6 +610,26 @@ function profileRouteInventorySummaryMarkdown(result) {
|
|
|
599
610
|
}
|
|
600
611
|
return lines;
|
|
601
612
|
}
|
|
613
|
+
function profileLinkStatusSummaryMarkdown(result) {
|
|
614
|
+
const linkStatusChecks = result.checks.filter((check) => check.type === "link_status" || check.type === "artifact_link_status");
|
|
615
|
+
const lines = [];
|
|
616
|
+
for (const check of linkStatusChecks) {
|
|
617
|
+
const evidence = cliRecord(check.evidence);
|
|
618
|
+
if (!evidence) continue;
|
|
619
|
+
const label = check.label || check.type;
|
|
620
|
+
const selector = cliString(evidence.selector);
|
|
621
|
+
const viewports = Array.isArray(evidence.viewports) ? evidence.viewports.map(cliRecord).filter((viewport) => Boolean(viewport)) : [];
|
|
622
|
+
const totals = viewports.map((viewport) => cliFiniteNumber(viewport.total_count)).filter((count) => count !== void 0);
|
|
623
|
+
const okTotal = viewports.reduce((sum, viewport) => sum + (cliFiniteNumber(viewport.ok_count) || 0), 0);
|
|
624
|
+
const failedTotal = viewports.reduce((sum, viewport) => sum + (cliFiniteNumber(viewport.failed_count) || 0), 0);
|
|
625
|
+
const truncatedTotal = viewports.filter((viewport) => viewport.truncated === true).length;
|
|
626
|
+
const countText = totals.length ? totals.join("/") : "unknown";
|
|
627
|
+
lines.push(
|
|
628
|
+
`- ${label}${selector ? ` ${markdownInlineCode(selector)}` : ""}: links ${countText}, ok ${okTotal}, failures ${failedTotal}${truncatedTotal ? `, truncated viewports ${truncatedTotal}` : ""}`
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
return lines;
|
|
632
|
+
}
|
|
602
633
|
function writeProfileOutput(outputDir, result) {
|
|
603
634
|
if (!outputDir) return;
|
|
604
635
|
mkdirSync(outputDir, { recursive: true });
|
package/dist/index.cjs
CHANGED
|
@@ -8755,6 +8755,8 @@ var RIDDLE_PROOF_PROFILE_CHECK_TYPES = [
|
|
|
8755
8755
|
"frame_no_horizontal_overflow",
|
|
8756
8756
|
"text_visible",
|
|
8757
8757
|
"text_absent",
|
|
8758
|
+
"link_status",
|
|
8759
|
+
"artifact_link_status",
|
|
8758
8760
|
"route_inventory",
|
|
8759
8761
|
"no_horizontal_overflow",
|
|
8760
8762
|
"no_mobile_horizontal_overflow",
|
|
@@ -9419,6 +9421,29 @@ function normalizeStringList(value, label) {
|
|
|
9419
9421
|
if (!values.length) throw new Error(`${label} must contain non-empty strings.`);
|
|
9420
9422
|
return values;
|
|
9421
9423
|
}
|
|
9424
|
+
function normalizeHttpStatus(value, label) {
|
|
9425
|
+
if (value === void 0) return void 0;
|
|
9426
|
+
const status = numberValue3(value);
|
|
9427
|
+
if (status === void 0 || !Number.isInteger(status) || status < 100 || status > 599) {
|
|
9428
|
+
throw new Error(`${label} must be an HTTP status code.`);
|
|
9429
|
+
}
|
|
9430
|
+
return status;
|
|
9431
|
+
}
|
|
9432
|
+
function normalizeHttpStatuses(value, label) {
|
|
9433
|
+
if (value === void 0) return void 0;
|
|
9434
|
+
if (!Array.isArray(value)) throw new Error(`${label} must be an array.`);
|
|
9435
|
+
if (!value.length) throw new Error(`${label} must not be empty.`);
|
|
9436
|
+
const statuses = value.map((item, index) => normalizeHttpStatus(item, `${label}[${index}]`));
|
|
9437
|
+
return Array.from(new Set(statuses));
|
|
9438
|
+
}
|
|
9439
|
+
function normalizePositiveInteger(value, label, max) {
|
|
9440
|
+
if (value === void 0) return void 0;
|
|
9441
|
+
const number = numberValue3(value);
|
|
9442
|
+
if (number === void 0 || !Number.isInteger(number) || number < 1 || max !== void 0 && number > max) {
|
|
9443
|
+
throw new Error(`${label} must be an integer from 1 to ${max ?? "unbounded"}.`);
|
|
9444
|
+
}
|
|
9445
|
+
return number;
|
|
9446
|
+
}
|
|
9422
9447
|
function validateRegexPatterns(patterns, label) {
|
|
9423
9448
|
for (const pattern of patterns || []) {
|
|
9424
9449
|
try {
|
|
@@ -9462,7 +9487,8 @@ function normalizeCheck(input, index) {
|
|
|
9462
9487
|
if (type === "url_search_param_equals" && expectedValue === void 0) {
|
|
9463
9488
|
throw new Error(`checks[${index}] url_search_param_equals requires expected_value.`);
|
|
9464
9489
|
}
|
|
9465
|
-
|
|
9490
|
+
const minCount = numberValue3(input.min_count) ?? numberValue3(input.minCount);
|
|
9491
|
+
if (type === "selector_count_at_least" && minCount === void 0) {
|
|
9466
9492
|
throw new Error(`checks[${index}] selector_count_at_least requires min_count.`);
|
|
9467
9493
|
}
|
|
9468
9494
|
const expectedCount = numberValue3(input.expected_count) ?? numberValue3(input.expectedCount) ?? numberValue3(input.count);
|
|
@@ -9478,6 +9504,21 @@ function normalizeCheck(input, index) {
|
|
|
9478
9504
|
if (type === "route_inventory" && !expectedRoutes?.length) {
|
|
9479
9505
|
throw new Error(`checks[${index}] route_inventory requires expected_routes.`);
|
|
9480
9506
|
}
|
|
9507
|
+
const isLinkStatusCheck = type === "link_status" || type === "artifact_link_status";
|
|
9508
|
+
const expectedStatus = isLinkStatusCheck ? normalizeHttpStatus(input.expected_status ?? input.expectedStatus ?? input.status, `checks[${index}] expected_status`) : void 0;
|
|
9509
|
+
const allowedStatuses = isLinkStatusCheck ? normalizeHttpStatuses(
|
|
9510
|
+
input.allowed_statuses ?? input.allowedStatuses ?? input.expected_statuses ?? input.expectedStatuses,
|
|
9511
|
+
`checks[${index}] allowed_statuses`
|
|
9512
|
+
) : void 0;
|
|
9513
|
+
const maxLinks = isLinkStatusCheck ? normalizePositiveInteger(input.max_links ?? input.maxLinks ?? input.limit, `checks[${index}] max_links`, 500) : void 0;
|
|
9514
|
+
if (isLinkStatusCheck) {
|
|
9515
|
+
if (minCount !== void 0 && (!Number.isInteger(minCount) || minCount < 0)) {
|
|
9516
|
+
throw new Error(`checks[${index}] ${type} min_count must be a non-negative integer.`);
|
|
9517
|
+
}
|
|
9518
|
+
if (expectedCount !== void 0 && (!Number.isInteger(expectedCount) || expectedCount < 0)) {
|
|
9519
|
+
throw new Error(`checks[${index}] ${type} expected_count must be a non-negative integer.`);
|
|
9520
|
+
}
|
|
9521
|
+
}
|
|
9481
9522
|
return {
|
|
9482
9523
|
type,
|
|
9483
9524
|
label: stringValue5(input.label),
|
|
@@ -9503,8 +9544,15 @@ function normalizeCheck(input, index) {
|
|
|
9503
9544
|
allowed_console_patterns: normalizeStringList(input.allowed_console_patterns ?? input.allowedConsolePatterns ?? input.allow_console_patterns ?? input.allowConsolePatterns, `checks[${index}] allowed_console_patterns`),
|
|
9504
9545
|
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`),
|
|
9505
9546
|
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`),
|
|
9506
|
-
min_count:
|
|
9547
|
+
min_count: minCount,
|
|
9507
9548
|
expected_count: expectedCount,
|
|
9549
|
+
expected_status: expectedStatus,
|
|
9550
|
+
allowed_statuses: allowedStatuses,
|
|
9551
|
+
max_links: maxLinks,
|
|
9552
|
+
same_origin_only: isLinkStatusCheck ? input.same_origin_only === true || input.sameOriginOnly === true : void 0,
|
|
9553
|
+
dedupe: isLinkStatusCheck ? input.dedupe === false ? false : true : void 0,
|
|
9554
|
+
require_nonzero_bytes: isLinkStatusCheck ? input.require_nonzero_bytes === true || input.requireNonzeroBytes === true : void 0,
|
|
9555
|
+
allow_get_fallback: isLinkStatusCheck ? input.allow_get_fallback === false || input.allowGetFallback === false ? false : true : void 0,
|
|
9508
9556
|
max_overflow_px: numberValue3(input.max_overflow_px),
|
|
9509
9557
|
timeout_ms: numberValue3(input.timeout_ms) ?? numberValue3(input.timeoutMs),
|
|
9510
9558
|
run_direct_routes: input.run_direct_routes === false || input.runDirectRoutes === false ? false : true,
|
|
@@ -9597,6 +9645,97 @@ function checkLabel(check) {
|
|
|
9597
9645
|
function selectorKey(check) {
|
|
9598
9646
|
return check.selector || "";
|
|
9599
9647
|
}
|
|
9648
|
+
function linkStatusSelector(check) {
|
|
9649
|
+
return check.selector || check.link_selector || "a[href]";
|
|
9650
|
+
}
|
|
9651
|
+
function linkStatusAllowedStatuses(check) {
|
|
9652
|
+
if (check.allowed_statuses?.length) return check.allowed_statuses;
|
|
9653
|
+
if (check.expected_status !== void 0) return [check.expected_status];
|
|
9654
|
+
return void 0;
|
|
9655
|
+
}
|
|
9656
|
+
function linkStatusIsAllowed(status, check) {
|
|
9657
|
+
if (status === void 0) return false;
|
|
9658
|
+
const allowed = linkStatusAllowedStatuses(check);
|
|
9659
|
+
return allowed?.length ? allowed.includes(status) : status >= 200 && status < 400;
|
|
9660
|
+
}
|
|
9661
|
+
function linkStatusResultOk(result, check) {
|
|
9662
|
+
const status = numberValue3(result.status);
|
|
9663
|
+
if (!linkStatusIsAllowed(status, check)) return false;
|
|
9664
|
+
if (stringValue5(result.error)) return false;
|
|
9665
|
+
if (result.ok === false) return false;
|
|
9666
|
+
if (check.require_nonzero_bytes) {
|
|
9667
|
+
const bytes = numberValue3(result.bytes);
|
|
9668
|
+
const contentLength = numberValue3(result.content_length);
|
|
9669
|
+
return bytes !== void 0 && bytes > 0 || contentLength !== void 0 && contentLength > 0;
|
|
9670
|
+
}
|
|
9671
|
+
return true;
|
|
9672
|
+
}
|
|
9673
|
+
function linkStatusEvidenceForCheck(viewport, check) {
|
|
9674
|
+
const evidence = viewport.link_statuses?.[linkStatusSelector(check)];
|
|
9675
|
+
return isRecord2(evidence) ? evidence : void 0;
|
|
9676
|
+
}
|
|
9677
|
+
function summarizeLinkStatusEvidence(viewport, check) {
|
|
9678
|
+
const linkEvidence = linkStatusEvidenceForCheck(viewport, check);
|
|
9679
|
+
if (!linkEvidence) {
|
|
9680
|
+
return {
|
|
9681
|
+
viewport: viewport.name,
|
|
9682
|
+
selector: linkStatusSelector(check),
|
|
9683
|
+
total_count: 0,
|
|
9684
|
+
ok_count: 0,
|
|
9685
|
+
failed_count: 1,
|
|
9686
|
+
failures: [{ code: "link_status_evidence_missing" }]
|
|
9687
|
+
};
|
|
9688
|
+
}
|
|
9689
|
+
const results = Array.isArray(linkEvidence.results) ? linkEvidence.results.filter(isRecord2) : [];
|
|
9690
|
+
const totalCount = numberValue3(linkEvidence.total_count) ?? results.length;
|
|
9691
|
+
const okCount = results.filter((result) => linkStatusResultOk(result, check)).length;
|
|
9692
|
+
const failures = results.filter((result) => !linkStatusResultOk(result, check)).map((result) => ({
|
|
9693
|
+
code: "link_status_failed",
|
|
9694
|
+
url: stringValue5(result.url) ?? null,
|
|
9695
|
+
status: numberValue3(result.status) ?? null,
|
|
9696
|
+
method: stringValue5(result.method) ?? null,
|
|
9697
|
+
error: stringValue5(result.error) ?? null,
|
|
9698
|
+
bytes: numberValue3(result.bytes) ?? numberValue3(result.content_length) ?? null
|
|
9699
|
+
}));
|
|
9700
|
+
if (stringValue5(linkEvidence.error)) {
|
|
9701
|
+
failures.push({ code: "link_status_capture_failed", error: stringValue5(linkEvidence.error) ?? "" });
|
|
9702
|
+
}
|
|
9703
|
+
const recordedFailedCount = numberValue3(linkEvidence.failed_count) ?? 0;
|
|
9704
|
+
if (!failures.length && recordedFailedCount > 0) {
|
|
9705
|
+
const recordedFailures = Array.isArray(linkEvidence.failures) ? linkEvidence.failures.slice(0, 20) : [];
|
|
9706
|
+
failures.push({
|
|
9707
|
+
code: "link_status_recorded_failures",
|
|
9708
|
+
failed_count: recordedFailedCount,
|
|
9709
|
+
failures: toJsonValue(recordedFailures)
|
|
9710
|
+
});
|
|
9711
|
+
}
|
|
9712
|
+
if (linkEvidence.truncated === true) {
|
|
9713
|
+
failures.push({
|
|
9714
|
+
code: "link_status_probe_truncated",
|
|
9715
|
+
discovered_count: numberValue3(linkEvidence.discovered_count) ?? totalCount,
|
|
9716
|
+
max_links: numberValue3(linkEvidence.max_links) ?? check.max_links ?? 100
|
|
9717
|
+
});
|
|
9718
|
+
}
|
|
9719
|
+
if (check.expected_count !== void 0 && totalCount !== check.expected_count) {
|
|
9720
|
+
failures.push({ code: "link_status_count_mismatch", expected: check.expected_count, actual: totalCount });
|
|
9721
|
+
}
|
|
9722
|
+
if (check.min_count !== void 0 && totalCount < check.min_count) {
|
|
9723
|
+
failures.push({ code: "link_status_count_below_minimum", min_count: check.min_count, actual: totalCount });
|
|
9724
|
+
}
|
|
9725
|
+
const statusCounts = isRecord2(linkEvidence.status_counts) ? linkEvidence.status_counts : {};
|
|
9726
|
+
return {
|
|
9727
|
+
viewport: viewport.name,
|
|
9728
|
+
selector: linkStatusSelector(check),
|
|
9729
|
+
total_count: totalCount,
|
|
9730
|
+
discovered_count: numberValue3(linkEvidence.discovered_count) ?? totalCount,
|
|
9731
|
+
ok_count: numberValue3(linkEvidence.ok_count) ?? okCount,
|
|
9732
|
+
failed_count: failures.length,
|
|
9733
|
+
truncated: linkEvidence.truncated === true,
|
|
9734
|
+
max_links: numberValue3(linkEvidence.max_links) ?? check.max_links ?? 100,
|
|
9735
|
+
status_counts: statusCounts,
|
|
9736
|
+
failures: failures.slice(0, 20)
|
|
9737
|
+
};
|
|
9738
|
+
}
|
|
9600
9739
|
function textKey(check) {
|
|
9601
9740
|
return check.pattern ? `pattern:${check.pattern}/${check.flags || ""}` : `text:${check.text || ""}`;
|
|
9602
9741
|
}
|
|
@@ -10076,6 +10215,26 @@ function assessCheckFromEvidence(check, evidence) {
|
|
|
10076
10215
|
message: failed ? `Text assertion failed in ${failed} viewport(s).` : void 0
|
|
10077
10216
|
};
|
|
10078
10217
|
}
|
|
10218
|
+
if (check.type === "link_status" || check.type === "artifact_link_status") {
|
|
10219
|
+
const selector = linkStatusSelector(check);
|
|
10220
|
+
const summaries = viewports.map((viewport) => summarizeLinkStatusEvidence(viewport, check));
|
|
10221
|
+
const failed = summaries.filter((summary) => (numberValue3(summary.failed_count) ?? 0) > 0);
|
|
10222
|
+
return {
|
|
10223
|
+
type: check.type,
|
|
10224
|
+
label: checkLabel(check),
|
|
10225
|
+
status: failed.length ? "failed" : "passed",
|
|
10226
|
+
evidence: {
|
|
10227
|
+
selector,
|
|
10228
|
+
expected_count: check.expected_count ?? null,
|
|
10229
|
+
min_count: check.min_count ?? null,
|
|
10230
|
+
allowed_statuses: linkStatusAllowedStatuses(check) || ["2xx", "3xx"],
|
|
10231
|
+
require_nonzero_bytes: check.require_nonzero_bytes === true,
|
|
10232
|
+
viewports: summaries.map((summary) => toJsonValue(summary)),
|
|
10233
|
+
failures: failed.flatMap((summary) => Array.isArray(summary.failures) ? summary.failures.map((failure) => toJsonValue({ viewport: stringValue5(summary.viewport) ?? null, failure })) : [])
|
|
10234
|
+
},
|
|
10235
|
+
message: failed.length ? `Link status failed in ${failed.length} viewport(s).` : void 0
|
|
10236
|
+
};
|
|
10237
|
+
}
|
|
10079
10238
|
if (check.type === "route_inventory") {
|
|
10080
10239
|
const inventories = viewports.map((viewport) => ({ viewport: viewport.name, inventory: viewport.route_inventory })).filter((item) => isRecord2(item.inventory));
|
|
10081
10240
|
if (!inventories.length) {
|
|
@@ -10658,6 +10817,98 @@ function textOrderMatch(texts, expectedTexts) {
|
|
|
10658
10817
|
}
|
|
10659
10818
|
return { matched: true, positions };
|
|
10660
10819
|
}
|
|
10820
|
+
function linkStatusSelector(check) {
|
|
10821
|
+
return check.selector || check.link_selector || "a[href]";
|
|
10822
|
+
}
|
|
10823
|
+
function linkStatusAllowedStatuses(check) {
|
|
10824
|
+
if (Array.isArray(check.allowed_statuses) && check.allowed_statuses.length) return check.allowed_statuses;
|
|
10825
|
+
if (typeof check.expected_status === "number" && Number.isFinite(check.expected_status)) return [check.expected_status];
|
|
10826
|
+
return undefined;
|
|
10827
|
+
}
|
|
10828
|
+
function linkStatusIsAllowed(status, check) {
|
|
10829
|
+
if (typeof status !== "number" || !Number.isFinite(status)) return false;
|
|
10830
|
+
const allowed = linkStatusAllowedStatuses(check);
|
|
10831
|
+
return Array.isArray(allowed) && allowed.length ? allowed.includes(status) : status >= 200 && status < 400;
|
|
10832
|
+
}
|
|
10833
|
+
function linkStatusResultOk(result, check) {
|
|
10834
|
+
if (!result || typeof result !== "object" || Array.isArray(result)) return false;
|
|
10835
|
+
if (!linkStatusIsAllowed(result.status, check)) return false;
|
|
10836
|
+
if (typeof result.error === "string" && result.error.trim()) return false;
|
|
10837
|
+
if (result.ok === false) return false;
|
|
10838
|
+
if (check.require_nonzero_bytes === true) {
|
|
10839
|
+
const bytes = typeof result.bytes === "number" && Number.isFinite(result.bytes) ? result.bytes : undefined;
|
|
10840
|
+
const contentLength = typeof result.content_length === "number" && Number.isFinite(result.content_length) ? result.content_length : undefined;
|
|
10841
|
+
return (bytes !== undefined && bytes > 0) || (contentLength !== undefined && contentLength > 0);
|
|
10842
|
+
}
|
|
10843
|
+
return true;
|
|
10844
|
+
}
|
|
10845
|
+
function summarizeLinkStatusEvidence(viewport, check) {
|
|
10846
|
+
const selector = linkStatusSelector(check);
|
|
10847
|
+
const linkEvidence = viewport && viewport.link_statuses && viewport.link_statuses[selector];
|
|
10848
|
+
if (!linkEvidence || typeof linkEvidence !== "object" || Array.isArray(linkEvidence)) {
|
|
10849
|
+
return {
|
|
10850
|
+
viewport: viewport && viewport.name,
|
|
10851
|
+
selector,
|
|
10852
|
+
total_count: 0,
|
|
10853
|
+
ok_count: 0,
|
|
10854
|
+
failed_count: 1,
|
|
10855
|
+
failures: [{ code: "link_status_evidence_missing" }],
|
|
10856
|
+
};
|
|
10857
|
+
}
|
|
10858
|
+
const results = Array.isArray(linkEvidence.results) ? linkEvidence.results.filter((result) => result && typeof result === "object" && !Array.isArray(result)) : [];
|
|
10859
|
+
const totalCount = typeof linkEvidence.total_count === "number" && Number.isFinite(linkEvidence.total_count) ? linkEvidence.total_count : results.length;
|
|
10860
|
+
const okCount = results.filter((result) => linkStatusResultOk(result, check)).length;
|
|
10861
|
+
const failures = results
|
|
10862
|
+
.filter((result) => !linkStatusResultOk(result, check))
|
|
10863
|
+
.map((result) => ({
|
|
10864
|
+
code: "link_status_failed",
|
|
10865
|
+
url: typeof result.url === "string" ? result.url : null,
|
|
10866
|
+
status: typeof result.status === "number" && Number.isFinite(result.status) ? result.status : null,
|
|
10867
|
+
method: typeof result.method === "string" ? result.method : null,
|
|
10868
|
+
error: typeof result.error === "string" ? result.error : null,
|
|
10869
|
+
bytes: typeof result.bytes === "number" && Number.isFinite(result.bytes)
|
|
10870
|
+
? result.bytes
|
|
10871
|
+
: typeof result.content_length === "number" && Number.isFinite(result.content_length)
|
|
10872
|
+
? result.content_length
|
|
10873
|
+
: null,
|
|
10874
|
+
}));
|
|
10875
|
+
if (typeof linkEvidence.error === "string" && linkEvidence.error.trim()) {
|
|
10876
|
+
failures.push({ code: "link_status_capture_failed", error: linkEvidence.error });
|
|
10877
|
+
}
|
|
10878
|
+
const recordedFailedCount = typeof linkEvidence.failed_count === "number" && Number.isFinite(linkEvidence.failed_count) ? linkEvidence.failed_count : 0;
|
|
10879
|
+
if (!failures.length && recordedFailedCount > 0) {
|
|
10880
|
+
failures.push({
|
|
10881
|
+
code: "link_status_recorded_failures",
|
|
10882
|
+
failed_count: recordedFailedCount,
|
|
10883
|
+
failures: Array.isArray(linkEvidence.failures) ? linkEvidence.failures.slice(0, 20) : [],
|
|
10884
|
+
});
|
|
10885
|
+
}
|
|
10886
|
+
if (linkEvidence.truncated === true) {
|
|
10887
|
+
failures.push({
|
|
10888
|
+
code: "link_status_probe_truncated",
|
|
10889
|
+
discovered_count: typeof linkEvidence.discovered_count === "number" ? linkEvidence.discovered_count : totalCount,
|
|
10890
|
+
max_links: typeof linkEvidence.max_links === "number" ? linkEvidence.max_links : check.max_links || 100,
|
|
10891
|
+
});
|
|
10892
|
+
}
|
|
10893
|
+
if (typeof check.expected_count === "number" && Number.isFinite(check.expected_count) && totalCount !== check.expected_count) {
|
|
10894
|
+
failures.push({ code: "link_status_count_mismatch", expected: check.expected_count, actual: totalCount });
|
|
10895
|
+
}
|
|
10896
|
+
if (typeof check.min_count === "number" && Number.isFinite(check.min_count) && totalCount < check.min_count) {
|
|
10897
|
+
failures.push({ code: "link_status_count_below_minimum", min_count: check.min_count, actual: totalCount });
|
|
10898
|
+
}
|
|
10899
|
+
return {
|
|
10900
|
+
viewport: viewport && viewport.name,
|
|
10901
|
+
selector,
|
|
10902
|
+
total_count: totalCount,
|
|
10903
|
+
discovered_count: typeof linkEvidence.discovered_count === "number" ? linkEvidence.discovered_count : totalCount,
|
|
10904
|
+
ok_count: typeof linkEvidence.ok_count === "number" ? linkEvidence.ok_count : okCount,
|
|
10905
|
+
failed_count: failures.length,
|
|
10906
|
+
truncated: linkEvidence.truncated === true,
|
|
10907
|
+
max_links: typeof linkEvidence.max_links === "number" ? linkEvidence.max_links : check.max_links || 100,
|
|
10908
|
+
status_counts: linkEvidence.status_counts && typeof linkEvidence.status_counts === "object" && !Array.isArray(linkEvidence.status_counts) ? linkEvidence.status_counts : {},
|
|
10909
|
+
failures: failures.slice(0, 20),
|
|
10910
|
+
};
|
|
10911
|
+
}
|
|
10661
10912
|
function frameEvidenceForSelector(viewport, selector) {
|
|
10662
10913
|
const container = viewport.frames && viewport.frames[selector || ""];
|
|
10663
10914
|
if (!container || typeof container !== "object" || Array.isArray(container)) return [];
|
|
@@ -11311,6 +11562,29 @@ function assessProfile(profile, evidence) {
|
|
|
11311
11562
|
});
|
|
11312
11563
|
continue;
|
|
11313
11564
|
}
|
|
11565
|
+
if (check.type === "link_status" || check.type === "artifact_link_status") {
|
|
11566
|
+
const selector = linkStatusSelector(check);
|
|
11567
|
+
const summaries = checkViewports.map((viewport) => summarizeLinkStatusEvidence(viewport, check));
|
|
11568
|
+
const failed = summaries.filter((summary) => summary.failed_count > 0);
|
|
11569
|
+
checks.push({
|
|
11570
|
+
type: check.type,
|
|
11571
|
+
label: check.label || check.type,
|
|
11572
|
+
status: failed.length ? "failed" : "passed",
|
|
11573
|
+
evidence: {
|
|
11574
|
+
selector,
|
|
11575
|
+
expected_count: check.expected_count ?? null,
|
|
11576
|
+
min_count: check.min_count ?? null,
|
|
11577
|
+
allowed_statuses: linkStatusAllowedStatuses(check) || ["2xx", "3xx"],
|
|
11578
|
+
require_nonzero_bytes: check.require_nonzero_bytes === true,
|
|
11579
|
+
viewports: summaries,
|
|
11580
|
+
failures: failed.flatMap((summary) => Array.isArray(summary.failures)
|
|
11581
|
+
? summary.failures.map((failure) => ({ viewport: summary.viewport || null, failure }))
|
|
11582
|
+
: []),
|
|
11583
|
+
},
|
|
11584
|
+
message: failed.length ? "Link status failed in " + failed.length + " viewport(s)." : undefined,
|
|
11585
|
+
});
|
|
11586
|
+
continue;
|
|
11587
|
+
}
|
|
11314
11588
|
if (check.type === "route_inventory") {
|
|
11315
11589
|
const inventories = checkViewports
|
|
11316
11590
|
.map((viewport) => ({ viewport: viewport.name, inventory: viewport.route_inventory }))
|
|
@@ -12369,6 +12643,196 @@ async function selectorTextSequence(selector) {
|
|
|
12369
12643
|
};
|
|
12370
12644
|
}).catch((error) => ({ count: 0, visible_count: 0, texts: [], visible_texts: [], error: String(error && error.message ? error.message : error).slice(0, 500) }));
|
|
12371
12645
|
}
|
|
12646
|
+
function linkProbeMaxLinks(check) {
|
|
12647
|
+
const value = Number(check.max_links || check.maxLinks || check.limit || 100);
|
|
12648
|
+
return Number.isInteger(value) && value > 0 ? Math.min(value, 500) : 100;
|
|
12649
|
+
}
|
|
12650
|
+
function linkProbeDedupe(check) {
|
|
12651
|
+
return check.dedupe !== false;
|
|
12652
|
+
}
|
|
12653
|
+
function linkProbeSameOriginOnly(check) {
|
|
12654
|
+
return check.same_origin_only === true;
|
|
12655
|
+
}
|
|
12656
|
+
async function collectLinkCandidates(selector) {
|
|
12657
|
+
return page.locator(selector).evaluateAll((elements) => {
|
|
12658
|
+
const compact = (value, limit) => String(value || "").replace(/\s+/g, " ").trim().slice(0, limit || 160);
|
|
12659
|
+
return elements.map((element, index) => {
|
|
12660
|
+
const tag = element && element.tagName ? element.tagName.toLowerCase() : "element";
|
|
12661
|
+
const href = element && typeof element.href === "string" ? element.href : "";
|
|
12662
|
+
const src = element && typeof element.src === "string" ? element.src : "";
|
|
12663
|
+
const currentSrc = element && typeof element.currentSrc === "string" ? element.currentSrc : "";
|
|
12664
|
+
const attrHref = element && typeof element.getAttribute === "function" ? element.getAttribute("href") || "" : "";
|
|
12665
|
+
const attrSrc = element && typeof element.getAttribute === "function" ? element.getAttribute("src") || "" : "";
|
|
12666
|
+
const attrPoster = element && typeof element.getAttribute === "function" ? element.getAttribute("poster") || "" : "";
|
|
12667
|
+
const raw = href || currentSrc || src || attrHref || attrSrc || attrPoster;
|
|
12668
|
+
if (!raw) return null;
|
|
12669
|
+
let url = "";
|
|
12670
|
+
try {
|
|
12671
|
+
url = new URL(raw, location.href).href;
|
|
12672
|
+
} catch {}
|
|
12673
|
+
if (!url) return null;
|
|
12674
|
+
return {
|
|
12675
|
+
index,
|
|
12676
|
+
tag,
|
|
12677
|
+
url,
|
|
12678
|
+
raw,
|
|
12679
|
+
text: compact(element.innerText || element.textContent || "", 160),
|
|
12680
|
+
alt: compact(element.getAttribute && element.getAttribute("alt"), 80),
|
|
12681
|
+
};
|
|
12682
|
+
}).filter(Boolean);
|
|
12683
|
+
}).catch((error) => ({ error: String(error && error.message ? error.message : error).slice(0, 500) }));
|
|
12684
|
+
}
|
|
12685
|
+
function linkProbeAllowed(status, check) {
|
|
12686
|
+
if (typeof status !== "number" || !Number.isFinite(status)) return false;
|
|
12687
|
+
const allowed = Array.isArray(check.allowed_statuses) && check.allowed_statuses.length
|
|
12688
|
+
? check.allowed_statuses
|
|
12689
|
+
: typeof check.expected_status === "number" && Number.isFinite(check.expected_status)
|
|
12690
|
+
? [check.expected_status]
|
|
12691
|
+
: null;
|
|
12692
|
+
return allowed ? allowed.includes(status) : status >= 200 && status < 400;
|
|
12693
|
+
}
|
|
12694
|
+
function linkProbeResponseFields(response, method) {
|
|
12695
|
+
const contentLengthHeader = response.headers && typeof response.headers.get === "function" ? response.headers.get("content-length") : null;
|
|
12696
|
+
const contentLength = contentLengthHeader && /^\d+$/.test(contentLengthHeader) ? Number(contentLengthHeader) : null;
|
|
12697
|
+
return {
|
|
12698
|
+
method,
|
|
12699
|
+
status: response.status,
|
|
12700
|
+
redirected: Boolean(response.redirected),
|
|
12701
|
+
final_url: response.url || null,
|
|
12702
|
+
content_type: response.headers && typeof response.headers.get === "function" ? response.headers.get("content-type") : null,
|
|
12703
|
+
content_length: contentLength,
|
|
12704
|
+
};
|
|
12705
|
+
}
|
|
12706
|
+
async function probeLinkStatus(candidate, check) {
|
|
12707
|
+
const requireNonzeroBytes = check.require_nonzero_bytes === true;
|
|
12708
|
+
const allowGetFallback = check.allow_get_fallback !== false;
|
|
12709
|
+
const result = {
|
|
12710
|
+
url: candidate.url,
|
|
12711
|
+
tag: candidate.tag,
|
|
12712
|
+
text: candidate.text || null,
|
|
12713
|
+
status: null,
|
|
12714
|
+
method: null,
|
|
12715
|
+
ok: false,
|
|
12716
|
+
content_type: null,
|
|
12717
|
+
content_length: null,
|
|
12718
|
+
bytes: null,
|
|
12719
|
+
redirected: false,
|
|
12720
|
+
final_url: null,
|
|
12721
|
+
error: null,
|
|
12722
|
+
};
|
|
12723
|
+
const applyResponse = async (response, method, readBytes) => {
|
|
12724
|
+
Object.assign(result, linkProbeResponseFields(response, method));
|
|
12725
|
+
if (readBytes || requireNonzeroBytes) {
|
|
12726
|
+
try {
|
|
12727
|
+
const buffer = await response.arrayBuffer();
|
|
12728
|
+
result.bytes = buffer.byteLength;
|
|
12729
|
+
} catch (error) {
|
|
12730
|
+
result.error = String(error && error.message ? error.message : error).slice(0, 500);
|
|
12731
|
+
}
|
|
12732
|
+
}
|
|
12733
|
+
result.ok = linkProbeAllowed(result.status, check)
|
|
12734
|
+
&& (!requireNonzeroBytes || (typeof result.bytes === "number" ? result.bytes > 0 : typeof result.content_length === "number" && result.content_length > 0))
|
|
12735
|
+
&& !result.error;
|
|
12736
|
+
};
|
|
12737
|
+
try {
|
|
12738
|
+
const response = await fetch(candidate.url, { method: "HEAD", redirect: "follow", cache: "no-store" });
|
|
12739
|
+
await applyResponse(response, "HEAD", false);
|
|
12740
|
+
if (result.ok || !allowGetFallback) return result;
|
|
12741
|
+
} catch (error) {
|
|
12742
|
+
result.error = String(error && error.message ? error.message : error).slice(0, 500);
|
|
12743
|
+
if (!allowGetFallback) return result;
|
|
12744
|
+
}
|
|
12745
|
+
try {
|
|
12746
|
+
result.error = null;
|
|
12747
|
+
const response = await fetch(candidate.url, {
|
|
12748
|
+
method: "GET",
|
|
12749
|
+
redirect: "follow",
|
|
12750
|
+
cache: "no-store",
|
|
12751
|
+
headers: { Range: "bytes=0-0" },
|
|
12752
|
+
});
|
|
12753
|
+
await applyResponse(response, "GET", requireNonzeroBytes);
|
|
12754
|
+
return result;
|
|
12755
|
+
} catch (error) {
|
|
12756
|
+
result.error = String(error && error.message ? error.message : error).slice(0, 500);
|
|
12757
|
+
result.ok = false;
|
|
12758
|
+
return result;
|
|
12759
|
+
}
|
|
12760
|
+
}
|
|
12761
|
+
async function collectLinkStatus(check) {
|
|
12762
|
+
const selector = linkStatusSelector(check);
|
|
12763
|
+
const candidateResult = await collectLinkCandidates(selector);
|
|
12764
|
+
if (candidateResult && candidateResult.error) {
|
|
12765
|
+
return {
|
|
12766
|
+
version: "riddle-proof.link-status.v1",
|
|
12767
|
+
selector,
|
|
12768
|
+
total_count: 0,
|
|
12769
|
+
discovered_count: 0,
|
|
12770
|
+
ok_count: 0,
|
|
12771
|
+
failed_count: 1,
|
|
12772
|
+
failures: [{ code: "link_status_capture_failed", error: candidateResult.error }],
|
|
12773
|
+
results: [],
|
|
12774
|
+
status_counts: {},
|
|
12775
|
+
error: candidateResult.error,
|
|
12776
|
+
};
|
|
12777
|
+
}
|
|
12778
|
+
const baseUrl = page.url() || targetUrl;
|
|
12779
|
+
let candidates = Array.isArray(candidateResult) ? candidateResult : [];
|
|
12780
|
+
if (linkProbeSameOriginOnly(check)) {
|
|
12781
|
+
const origin = new URL(baseUrl).origin;
|
|
12782
|
+
candidates = candidates.filter((candidate) => {
|
|
12783
|
+
try { return new URL(candidate.url).origin === origin; } catch { return false; }
|
|
12784
|
+
});
|
|
12785
|
+
}
|
|
12786
|
+
const discoveredCount = candidates.length;
|
|
12787
|
+
if (linkProbeDedupe(check)) {
|
|
12788
|
+
const seen = new Set();
|
|
12789
|
+
candidates = candidates.filter((candidate) => {
|
|
12790
|
+
if (seen.has(candidate.url)) return false;
|
|
12791
|
+
seen.add(candidate.url);
|
|
12792
|
+
return true;
|
|
12793
|
+
});
|
|
12794
|
+
}
|
|
12795
|
+
const maxLinks = linkProbeMaxLinks(check);
|
|
12796
|
+
const selected = candidates.slice(0, maxLinks);
|
|
12797
|
+
const results = [];
|
|
12798
|
+
for (const candidate of selected) {
|
|
12799
|
+
results.push(await probeLinkStatus(candidate, check));
|
|
12800
|
+
}
|
|
12801
|
+
const failures = results.filter((result) => !result.ok).map((result) => ({
|
|
12802
|
+
code: "link_status_failed",
|
|
12803
|
+
url: result.url,
|
|
12804
|
+
status: result.status,
|
|
12805
|
+
method: result.method,
|
|
12806
|
+
error: result.error,
|
|
12807
|
+
bytes: result.bytes == null ? result.content_length : result.bytes,
|
|
12808
|
+
}));
|
|
12809
|
+
const statusCounts = {};
|
|
12810
|
+
for (const result of results) {
|
|
12811
|
+
const key = result.status == null ? "error" : String(result.status);
|
|
12812
|
+
statusCounts[key] = (statusCounts[key] || 0) + 1;
|
|
12813
|
+
}
|
|
12814
|
+
return {
|
|
12815
|
+
version: "riddle-proof.link-status.v1",
|
|
12816
|
+
selector,
|
|
12817
|
+
max_links: maxLinks,
|
|
12818
|
+
same_origin_only: linkProbeSameOriginOnly(check),
|
|
12819
|
+
dedupe: linkProbeDedupe(check),
|
|
12820
|
+
require_nonzero_bytes: check.require_nonzero_bytes === true,
|
|
12821
|
+
allowed_statuses: Array.isArray(check.allowed_statuses) && check.allowed_statuses.length
|
|
12822
|
+
? check.allowed_statuses
|
|
12823
|
+
: typeof check.expected_status === "number"
|
|
12824
|
+
? [check.expected_status]
|
|
12825
|
+
: ["2xx", "3xx"],
|
|
12826
|
+
discovered_count: discoveredCount,
|
|
12827
|
+
total_count: selected.length,
|
|
12828
|
+
truncated: candidates.length > selected.length,
|
|
12829
|
+
ok_count: results.filter((result) => result.ok).length,
|
|
12830
|
+
failed_count: failures.length,
|
|
12831
|
+
status_counts: statusCounts,
|
|
12832
|
+
failures: failures.slice(0, 20),
|
|
12833
|
+
results,
|
|
12834
|
+
};
|
|
12835
|
+
}
|
|
12372
12836
|
async function frameEvidence(selector) {
|
|
12373
12837
|
const result = { selector, count: 0, frame_count: 0, frames: [], errors: [] };
|
|
12374
12838
|
let handles = [];
|
|
@@ -12888,6 +13352,7 @@ async function captureViewport(viewport) {
|
|
|
12888
13352
|
const frames = {};
|
|
12889
13353
|
const text_sequences = {};
|
|
12890
13354
|
const text_matches = {};
|
|
13355
|
+
const link_statuses = {};
|
|
12891
13356
|
for (const check of profile.checks || []) {
|
|
12892
13357
|
if (
|
|
12893
13358
|
(
|
|
@@ -12912,6 +13377,10 @@ async function captureViewport(viewport) {
|
|
|
12912
13377
|
selectors[check.selector] = selectors[check.selector] || await selectorStats(check.selector);
|
|
12913
13378
|
frames[check.selector] = frames[check.selector] || await frameEvidence(check.selector);
|
|
12914
13379
|
}
|
|
13380
|
+
if (check.type === "link_status" || check.type === "artifact_link_status") {
|
|
13381
|
+
const selector = linkStatusSelector(check);
|
|
13382
|
+
link_statuses[selector] = link_statuses[selector] || await collectLinkStatus(check);
|
|
13383
|
+
}
|
|
12915
13384
|
}
|
|
12916
13385
|
const screenshotLabel = profileSlug + "-" + viewport.name;
|
|
12917
13386
|
try {
|
|
@@ -12975,6 +13444,7 @@ async function captureViewport(viewport) {
|
|
|
12975
13444
|
frames,
|
|
12976
13445
|
text_sequences,
|
|
12977
13446
|
text_matches,
|
|
13447
|
+
link_statuses,
|
|
12978
13448
|
route_inventory: routeInventory,
|
|
12979
13449
|
setup_action_results: setupActionResults,
|
|
12980
13450
|
screenshot_label: screenshotLabel,
|
|
@@ -13023,6 +13493,18 @@ function buildProfileEvidence(currentViewports) {
|
|
|
13023
13493
|
),
|
|
13024
13494
|
})),
|
|
13025
13495
|
})),
|
|
13496
|
+
link_status: currentViewports
|
|
13497
|
+
.filter((viewport) => viewport.link_statuses)
|
|
13498
|
+
.map((viewport) => ({
|
|
13499
|
+
viewport: viewport.name,
|
|
13500
|
+
selectors: Object.entries(viewport.link_statuses || {}).map(([selector, statusSet]) => ({
|
|
13501
|
+
selector,
|
|
13502
|
+
total_count: statusSet && statusSet.total_count,
|
|
13503
|
+
ok_count: statusSet && statusSet.ok_count,
|
|
13504
|
+
failed_count: statusSet && statusSet.failed_count,
|
|
13505
|
+
truncated: statusSet && statusSet.truncated === true,
|
|
13506
|
+
})),
|
|
13507
|
+
})),
|
|
13026
13508
|
route_inventory: currentViewports
|
|
13027
13509
|
.filter((viewport) => viewport.route_inventory)
|
|
13028
13510
|
.map((viewport) => ({
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
resolveRiddleProofProfileTimeoutSec,
|
|
59
59
|
slugifyRiddleProofProfileName,
|
|
60
60
|
summarizeRiddleProofProfileResult
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-4FMBHM4E.js";
|
|
62
62
|
import {
|
|
63
63
|
DEFAULT_RIDDLE_API_BASE_URL,
|
|
64
64
|
DEFAULT_RIDDLE_API_KEY_FILE,
|