nfunc-mcp 0.3.0 → 0.5.0
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 +121 -379
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mappers/a11yDedupe.js +38 -7
- package/dist/mappers/a11yDedupe.js.map +1 -1
- package/dist/mappers/defectFormatter.d.ts +9 -1
- package/dist/mappers/defectFormatter.js +53 -13
- package/dist/mappers/defectFormatter.js.map +1 -1
- package/dist/mappers/labFieldComparator.d.ts +62 -0
- package/dist/mappers/labFieldComparator.js +134 -0
- package/dist/mappers/labFieldComparator.js.map +1 -0
- package/dist/mappers/priorityMapper.d.ts +42 -0
- package/dist/mappers/priorityMapper.js +58 -0
- package/dist/mappers/priorityMapper.js.map +1 -1
- package/dist/mappers/psiAggregator.d.ts +130 -0
- package/dist/mappers/psiAggregator.js +293 -0
- package/dist/mappers/psiAggregator.js.map +1 -0
- package/dist/mappers/runComparator.d.ts +85 -0
- package/dist/mappers/runComparator.js +165 -0
- package/dist/mappers/runComparator.js.map +1 -0
- package/dist/mappers/wcagLevels.d.ts +73 -0
- package/dist/mappers/wcagLevels.js +320 -0
- package/dist/mappers/wcagLevels.js.map +1 -0
- package/dist/mappers/webVitalsMapper.d.ts +52 -0
- package/dist/mappers/webVitalsMapper.js +131 -0
- package/dist/mappers/webVitalsMapper.js.map +1 -0
- package/dist/tools/accessibility.d.ts +1 -0
- package/dist/tools/accessibility.js +488 -63
- package/dist/tools/accessibility.js.map +1 -1
- package/dist/tools/lighthouse.js +370 -102
- package/dist/tools/lighthouse.js.map +1 -1
- package/dist/tools/performanceAudit.d.ts +2 -0
- package/dist/tools/performanceAudit.js +446 -0
- package/dist/tools/performanceAudit.js.map +1 -0
- package/dist/tools/performanceAuditPlan.d.ts +2 -0
- package/dist/tools/performanceAuditPlan.js +438 -0
- package/dist/tools/performanceAuditPlan.js.map +1 -0
- package/dist/utils/batchState.d.ts +75 -0
- package/dist/utils/batchState.js +128 -0
- package/dist/utils/batchState.js.map +1 -0
- package/dist/utils/csvReader.d.ts +20 -0
- package/dist/utils/csvReader.js +172 -0
- package/dist/utils/csvReader.js.map +1 -0
- package/dist/utils/httpClient.d.ts +84 -0
- package/dist/utils/httpClient.js +171 -0
- package/dist/utils/httpClient.js.map +1 -0
- package/dist/utils/outputParsers.js +26 -30
- package/dist/utils/outputParsers.js.map +1 -1
- package/dist/utils/psiAuth.d.ts +26 -0
- package/dist/utils/psiAuth.js +36 -0
- package/dist/utils/psiAuth.js.map +1 -0
- package/dist/utils/psiParser.d.ts +135 -0
- package/dist/utils/psiParser.js +200 -0
- package/dist/utils/psiParser.js.map +1 -0
- package/dist/utils/publicUrl.d.ts +17 -0
- package/dist/utils/publicUrl.js +115 -0
- package/dist/utils/publicUrl.js.map +1 -0
- package/dist/utils/sitemapReader.d.ts +27 -0
- package/dist/utils/sitemapReader.js +272 -0
- package/dist/utils/sitemapReader.js.map +1 -0
- package/dist/utils/urlClassifier.d.ts +45 -0
- package/dist/utils/urlClassifier.js +267 -0
- package/dist/utils/urlClassifier.js.map +1 -0
- package/dist/utils/urlInput.d.ts +30 -0
- package/dist/utils/urlInput.js +130 -0
- package/dist/utils/urlInput.js.map +1 -0
- package/docs/manual.md +769 -0
- package/docs/psi-report-spec.md +174 -0
- package/package.json +13 -3
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-run arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* This module owns every number that describes the audit as a whole, because
|
|
5
|
+
* that is precisely where reading JSON by hand goes wrong. The manual Five
|
|
6
|
+
* Below report got "TBT fails on 22/22 pages" right and the direction of the
|
|
7
|
+
* CrUX CLS disagreement backwards, in the same document — the first is a count
|
|
8
|
+
* and the second is a comparison, and a human doing 26 files will eventually
|
|
9
|
+
* miss one. Everything here is computed so the report can quote rather than
|
|
10
|
+
* derive.
|
|
11
|
+
*
|
|
12
|
+
* It also owns the two redundancy rules, because both need the page set in
|
|
13
|
+
* view. A single-URL audit should still report every failing metric; the
|
|
14
|
+
* repetition only exists across a set.
|
|
15
|
+
*/
|
|
16
|
+
import type { Finding } from "../types.js";
|
|
17
|
+
import type { LabMetrics, ParsedCrux, WebVital } from "../utils/psiParser.js";
|
|
18
|
+
import type { MetricComparison } from "./labFieldComparator.js";
|
|
19
|
+
export interface RunResult {
|
|
20
|
+
template: string;
|
|
21
|
+
label: string;
|
|
22
|
+
url: string;
|
|
23
|
+
strategy: string;
|
|
24
|
+
runs: number;
|
|
25
|
+
scores: Record<string, number>;
|
|
26
|
+
lab: LabMetrics;
|
|
27
|
+
field: ParsedCrux | null;
|
|
28
|
+
comparisons: MetricComparison[];
|
|
29
|
+
findings: Finding[];
|
|
30
|
+
report_file: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Rule 2 — component suppression.
|
|
34
|
+
*
|
|
35
|
+
* FCP is a component of LCP: if the largest element paints late, the first one
|
|
36
|
+
* usually did too. Across the Five Below batch the two co-occurred on 17 of 25
|
|
37
|
+
* runs and FCP never once reached P1, so an FCP finding alongside an LCP
|
|
38
|
+
* finding is two tickets describing one defect. The FCP measurement is kept as
|
|
39
|
+
* evidence on the LCP finding rather than discarded.
|
|
40
|
+
*
|
|
41
|
+
* TTFB is deliberately *not* treated this way. It fired on one run out of 25,
|
|
42
|
+
* which is the signature of a metric carrying independent information.
|
|
43
|
+
*/
|
|
44
|
+
export declare function suppressComponentFindings(findings: Finding[]): Finding[];
|
|
45
|
+
export interface SystemicResult {
|
|
46
|
+
findings: Finding[];
|
|
47
|
+
/** Vitals whose per-page findings this replaces. */
|
|
48
|
+
collapsedVitals: WebVital[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Rule 1 — systemic collapse.
|
|
52
|
+
*
|
|
53
|
+
* A vital rated below "good" on 80%+ of runs is describing the site, not any
|
|
54
|
+
* one page. INP failed on 25 of 25 Five Below runs with a 2.1x spread and a
|
|
55
|
+
* 316 ms median: twenty-five findings that each say "fix this page" when the
|
|
56
|
+
* true statement is "this site's interaction handling is uniformly mediocre".
|
|
57
|
+
*
|
|
58
|
+
* The threshold is deliberately well above a simple majority — a vital failing
|
|
59
|
+
* on half the pages is discriminating between them, and that is information
|
|
60
|
+
* worth keeping per page.
|
|
61
|
+
*
|
|
62
|
+
* Priority is the worst observed, not an average: a vital that is poor
|
|
63
|
+
* everywhere is not less urgent for being ubiquitous.
|
|
64
|
+
*/
|
|
65
|
+
export declare function collapseSystemicFindings(runs: RunResult[]): SystemicResult;
|
|
66
|
+
export interface PsiAggregate {
|
|
67
|
+
run_count: number;
|
|
68
|
+
pages: number;
|
|
69
|
+
captured_at: string;
|
|
70
|
+
by_strategy: Record<string, {
|
|
71
|
+
performance: {
|
|
72
|
+
mean: number;
|
|
73
|
+
min: number;
|
|
74
|
+
max: number;
|
|
75
|
+
};
|
|
76
|
+
}>;
|
|
77
|
+
by_template: Array<{
|
|
78
|
+
template: string;
|
|
79
|
+
label: string;
|
|
80
|
+
sampled: number;
|
|
81
|
+
performance_mean: Record<string, number>;
|
|
82
|
+
worst_url: string;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Lab metrics failing across the audited runs. Renamed from
|
|
86
|
+
* `universal_failures`, which was a lie on any site where a metric failed on
|
|
87
|
+
* some pages but not others — it reported a 25% failure rate under a name the
|
|
88
|
+
* report spec told the agent to treat as a headline finding. `universal` now
|
|
89
|
+
* says explicitly whether the "fails on essentially every page" claim holds.
|
|
90
|
+
*/
|
|
91
|
+
lab_metric_failures: Array<{
|
|
92
|
+
metric: string;
|
|
93
|
+
label: string;
|
|
94
|
+
failing: number;
|
|
95
|
+
of: number;
|
|
96
|
+
pct: number;
|
|
97
|
+
universal: boolean;
|
|
98
|
+
range: string;
|
|
99
|
+
threshold: string;
|
|
100
|
+
}>;
|
|
101
|
+
cwv_verdicts: {
|
|
102
|
+
pass: number;
|
|
103
|
+
needs_improvement: number;
|
|
104
|
+
fail: number;
|
|
105
|
+
};
|
|
106
|
+
lab_vs_field_summary: {
|
|
107
|
+
worse_in_field: Array<{
|
|
108
|
+
metric: string;
|
|
109
|
+
runs: number;
|
|
110
|
+
}>;
|
|
111
|
+
worse_in_lab: Array<{
|
|
112
|
+
metric: string;
|
|
113
|
+
runs: number;
|
|
114
|
+
}>;
|
|
115
|
+
confirmed: Array<{
|
|
116
|
+
metric: string;
|
|
117
|
+
runs: number;
|
|
118
|
+
}>;
|
|
119
|
+
no_field_data: number;
|
|
120
|
+
};
|
|
121
|
+
outliers: Array<{
|
|
122
|
+
url: string;
|
|
123
|
+
strategy: string;
|
|
124
|
+
metric: string;
|
|
125
|
+
value: string;
|
|
126
|
+
vs_median_multiple: number;
|
|
127
|
+
confidence: string;
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
130
|
+
export declare function aggregate(runs: RunResult[]): PsiAggregate;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-run arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* This module owns every number that describes the audit as a whole, because
|
|
5
|
+
* that is precisely where reading JSON by hand goes wrong. The manual Five
|
|
6
|
+
* Below report got "TBT fails on 22/22 pages" right and the direction of the
|
|
7
|
+
* CrUX CLS disagreement backwards, in the same document — the first is a count
|
|
8
|
+
* and the second is a comparison, and a human doing 26 files will eventually
|
|
9
|
+
* miss one. Everything here is computed so the report can quote rather than
|
|
10
|
+
* derive.
|
|
11
|
+
*
|
|
12
|
+
* It also owns the two redundancy rules, because both need the page set in
|
|
13
|
+
* view. A single-URL audit should still report every failing metric; the
|
|
14
|
+
* repetition only exists across a set.
|
|
15
|
+
*/
|
|
16
|
+
import { classifyVital, formatVitalValue, vitalLabel } from "./webVitalsMapper.js";
|
|
17
|
+
/** A vital failing on at least this share of runs is a candidate for collapse. */
|
|
18
|
+
const SYSTEMIC_THRESHOLD = 0.8;
|
|
19
|
+
/**
|
|
20
|
+
* ...but only if it also varies little between pages.
|
|
21
|
+
*
|
|
22
|
+
* Ubiquity alone is not enough, and the first implementation of this rule got
|
|
23
|
+
* it wrong: it collapsed CLS, which fails on 25 of 25 Five Below runs but
|
|
24
|
+
* ranges 0.18 to 0.85 — a 4.7x spread that is the single most page-specific
|
|
25
|
+
* signal in the dataset. Collapsing it would have deleted the finding the
|
|
26
|
+
* whole tool exists to surface.
|
|
27
|
+
*
|
|
28
|
+
* A shared-code characteristic looks the same everywhere: INP fails on every
|
|
29
|
+
* page within a 2.1x band. A per-page defect that happens to be widespread
|
|
30
|
+
* does not. So collapse requires both — fails nearly everywhere *and* barely
|
|
31
|
+
* moves between pages.
|
|
32
|
+
*/
|
|
33
|
+
const SYSTEMIC_MAX_SPREAD = 2.5;
|
|
34
|
+
/** Lab-only metrics with no field counterpart, needed for the universal-failure counts. */
|
|
35
|
+
const LAB_THRESHOLDS = {
|
|
36
|
+
tbtMs: { label: "Total Blocking Time", good: 200, unit: "ms" },
|
|
37
|
+
};
|
|
38
|
+
const PRIORITY_RANK = { P1: 0, P2: 1, P3: 2 };
|
|
39
|
+
function median(values) {
|
|
40
|
+
if (values.length === 0)
|
|
41
|
+
return 0;
|
|
42
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
43
|
+
const mid = Math.floor(sorted.length / 2);
|
|
44
|
+
return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
45
|
+
}
|
|
46
|
+
function mean(values) {
|
|
47
|
+
return values.length === 0 ? 0 : Math.round(values.reduce((a, b) => a + b, 0) / values.length);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Rule 2 — component suppression.
|
|
51
|
+
*
|
|
52
|
+
* FCP is a component of LCP: if the largest element paints late, the first one
|
|
53
|
+
* usually did too. Across the Five Below batch the two co-occurred on 17 of 25
|
|
54
|
+
* runs and FCP never once reached P1, so an FCP finding alongside an LCP
|
|
55
|
+
* finding is two tickets describing one defect. The FCP measurement is kept as
|
|
56
|
+
* evidence on the LCP finding rather than discarded.
|
|
57
|
+
*
|
|
58
|
+
* TTFB is deliberately *not* treated this way. It fired on one run out of 25,
|
|
59
|
+
* which is the signature of a metric carrying independent information.
|
|
60
|
+
*/
|
|
61
|
+
export function suppressComponentFindings(findings) {
|
|
62
|
+
const lcp = findings.find((f) => f.evidence.audit_id === "crux.lcp");
|
|
63
|
+
const fcp = findings.find((f) => f.evidence.audit_id === "crux.fcp");
|
|
64
|
+
if (!lcp || !fcp)
|
|
65
|
+
return findings;
|
|
66
|
+
lcp.evidence = {
|
|
67
|
+
...lcp.evidence,
|
|
68
|
+
supporting_fcp: fcp.evidence.value,
|
|
69
|
+
note: "First Contentful Paint is also below target; it is a component of this metric, not a separate defect.",
|
|
70
|
+
};
|
|
71
|
+
return findings.filter((f) => f !== fcp);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Rule 1 — systemic collapse.
|
|
75
|
+
*
|
|
76
|
+
* A vital rated below "good" on 80%+ of runs is describing the site, not any
|
|
77
|
+
* one page. INP failed on 25 of 25 Five Below runs with a 2.1x spread and a
|
|
78
|
+
* 316 ms median: twenty-five findings that each say "fix this page" when the
|
|
79
|
+
* true statement is "this site's interaction handling is uniformly mediocre".
|
|
80
|
+
*
|
|
81
|
+
* The threshold is deliberately well above a simple majority — a vital failing
|
|
82
|
+
* on half the pages is discriminating between them, and that is information
|
|
83
|
+
* worth keeping per page.
|
|
84
|
+
*
|
|
85
|
+
* Priority is the worst observed, not an average: a vital that is poor
|
|
86
|
+
* everywhere is not less urgent for being ubiquitous.
|
|
87
|
+
*/
|
|
88
|
+
export function collapseSystemicFindings(runs) {
|
|
89
|
+
const findings = [];
|
|
90
|
+
const collapsedVitals = [];
|
|
91
|
+
if (runs.length < 3)
|
|
92
|
+
return { findings, collapsedVitals };
|
|
93
|
+
const vitals = ["lcp", "inp", "cls", "fcp", "ttfb"];
|
|
94
|
+
for (const vital of vitals) {
|
|
95
|
+
// Only URL-level measurements can support a site-wide conclusion.
|
|
96
|
+
//
|
|
97
|
+
// Origin-level CrUX is *the same number* repeated for every page that falls
|
|
98
|
+
// back to it, so both tests below are guaranteed to pass on it: the failure
|
|
99
|
+
// rate is 100% and the spread is exactly 1.0x. That manufactured a
|
|
100
|
+
// "fails everywhere and varies little between pages" finding from what was
|
|
101
|
+
// literally one measurement copied across three runs. The spread gate is
|
|
102
|
+
// only meaningful over independent per-page data.
|
|
103
|
+
const measured = runs.filter((r) => r.field?.metrics[vital]?.source === "url");
|
|
104
|
+
if (measured.length < 3)
|
|
105
|
+
continue;
|
|
106
|
+
// Count runs that still carry a finding for this vital, not runs whose raw
|
|
107
|
+
// metric is below target. The two rules have to compose: FCP is folded into
|
|
108
|
+
// LCP by component suppression, and counting raw metrics resurrected it as
|
|
109
|
+
// a site-wide finding that per-page reporting had deliberately dropped.
|
|
110
|
+
const failing = measured.filter((r) => r.findings.some((f) => f.evidence.audit_id === `crux.${vital}`));
|
|
111
|
+
if (failing.length / measured.length < SYSTEMIC_THRESHOLD)
|
|
112
|
+
continue;
|
|
113
|
+
const values = failing.map((r) => r.field?.metrics[vital]?.p75 ?? 0);
|
|
114
|
+
// Spread gate. Guard against a zero floor, which would make any spread
|
|
115
|
+
// infinite and suppress the collapse for the wrong reason.
|
|
116
|
+
const low = Math.min(...values);
|
|
117
|
+
const high = Math.max(...values);
|
|
118
|
+
if (low > 0 && high / low > SYSTEMIC_MAX_SPREAD)
|
|
119
|
+
continue;
|
|
120
|
+
const worst = failing
|
|
121
|
+
.flatMap((r) => r.findings.filter((f) => f.evidence.audit_id === `crux.${vital}`))
|
|
122
|
+
.reduce((acc, f) => (PRIORITY_RANK[f.priority] < PRIORITY_RANK[acc] ? f.priority : acc), "P3");
|
|
123
|
+
const med = median(values);
|
|
124
|
+
const min = low;
|
|
125
|
+
const max = high;
|
|
126
|
+
collapsedVitals.push(vital);
|
|
127
|
+
findings.push({
|
|
128
|
+
priority: worst,
|
|
129
|
+
title: `${vitalLabel(vital)} is below target site-wide (${failing.length}/${measured.length} runs)`,
|
|
130
|
+
description: `Real users are below Google's ${vitalLabel(vital)} target on ` +
|
|
131
|
+
`${failing.length} of ${measured.length} audited page/device runs, with a median of ` +
|
|
132
|
+
`${formatVitalValue(vital, med)} and a range of ${formatVitalValue(vital, min)} to ` +
|
|
133
|
+
`${formatVitalValue(vital, max)}. Because it fails almost everywhere and varies little ` +
|
|
134
|
+
`between pages, this is a characteristic of the site's shared code rather than a defect ` +
|
|
135
|
+
`on any one template — fixing individual pages will not move it. Investigate the common ` +
|
|
136
|
+
`layer: the shared bundle, the third-party tags loaded on every page, or the base template.`,
|
|
137
|
+
evidence: {
|
|
138
|
+
audit_id: `crux.${vital}.systemic`,
|
|
139
|
+
value: formatVitalValue(vital, med),
|
|
140
|
+
failing_runs: failing.length,
|
|
141
|
+
total_runs: measured.length,
|
|
142
|
+
range: `${formatVitalValue(vital, min)}–${formatVitalValue(vital, max)}`,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return { findings, collapsedVitals };
|
|
147
|
+
}
|
|
148
|
+
/** Core Web Vitals verdict per run, field-first, matching the manual report's tiers. */
|
|
149
|
+
function cwvVerdict(run) {
|
|
150
|
+
const core = ["lcp", "inp", "cls"];
|
|
151
|
+
let failing = 0;
|
|
152
|
+
for (const vital of core) {
|
|
153
|
+
const fieldMetric = run.field?.metrics[vital];
|
|
154
|
+
if (fieldMetric) {
|
|
155
|
+
if (classifyVital(vital, fieldMetric.p75) !== "good")
|
|
156
|
+
failing++;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// INP has no lab fallback, so a run with no field INP is scored on what exists.
|
|
160
|
+
const labValue = vital === "lcp" ? run.lab.lcpMs : vital === "cls" ? run.lab.cls : null;
|
|
161
|
+
if (labValue !== null && classifyVital(vital, labValue) !== "good")
|
|
162
|
+
failing++;
|
|
163
|
+
}
|
|
164
|
+
if (failing === 0)
|
|
165
|
+
return "pass";
|
|
166
|
+
return failing === 1 ? "needs_improvement" : "fail";
|
|
167
|
+
}
|
|
168
|
+
export function aggregate(runs) {
|
|
169
|
+
const strategies = [...new Set(runs.map((r) => r.strategy))];
|
|
170
|
+
const by_strategy = {};
|
|
171
|
+
for (const strategy of strategies) {
|
|
172
|
+
const scores = runs
|
|
173
|
+
.filter((r) => r.strategy === strategy)
|
|
174
|
+
.map((r) => r.scores.performance)
|
|
175
|
+
.filter((n) => typeof n === "number");
|
|
176
|
+
if (scores.length === 0)
|
|
177
|
+
continue;
|
|
178
|
+
by_strategy[strategy] = {
|
|
179
|
+
performance: { mean: mean(scores), min: Math.min(...scores), max: Math.max(...scores) },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const templateIds = [...new Set(runs.map((r) => r.template))];
|
|
183
|
+
const by_template = templateIds.map((template) => {
|
|
184
|
+
const group = runs.filter((r) => r.template === template);
|
|
185
|
+
const performance_mean = {};
|
|
186
|
+
for (const strategy of strategies) {
|
|
187
|
+
const scores = group
|
|
188
|
+
.filter((r) => r.strategy === strategy)
|
|
189
|
+
.map((r) => r.scores.performance)
|
|
190
|
+
.filter((n) => typeof n === "number");
|
|
191
|
+
if (scores.length > 0)
|
|
192
|
+
performance_mean[strategy] = mean(scores);
|
|
193
|
+
}
|
|
194
|
+
const worst = [...group].sort((a, b) => (a.scores.performance ?? 100) - (b.scores.performance ?? 100))[0];
|
|
195
|
+
return {
|
|
196
|
+
template,
|
|
197
|
+
label: group[0].label,
|
|
198
|
+
sampled: new Set(group.map((r) => r.url)).size,
|
|
199
|
+
performance_mean,
|
|
200
|
+
worst_url: worst?.url ?? "",
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
// Lab metrics failing across the runs. At 100% this is the "22/22 fail TBT"
|
|
204
|
+
// line — the strongest sentence in the manual report, and the one most likely
|
|
205
|
+
// to be miscounted by hand. Below 80% it is not a headline; `universal` says
|
|
206
|
+
// which case a reader is looking at.
|
|
207
|
+
const lab_metric_failures = [];
|
|
208
|
+
for (const [key, spec] of Object.entries(LAB_THRESHOLDS)) {
|
|
209
|
+
const values = runs
|
|
210
|
+
.map((r) => r.lab[key])
|
|
211
|
+
.filter((v) => typeof v === "number");
|
|
212
|
+
if (values.length === 0)
|
|
213
|
+
continue;
|
|
214
|
+
const failing = values.filter((v) => v > spec.good);
|
|
215
|
+
if (failing.length === 0)
|
|
216
|
+
continue;
|
|
217
|
+
const pct = Math.round((failing.length / values.length) * 100);
|
|
218
|
+
lab_metric_failures.push({
|
|
219
|
+
metric: key,
|
|
220
|
+
label: spec.label,
|
|
221
|
+
failing: failing.length,
|
|
222
|
+
of: values.length,
|
|
223
|
+
pct,
|
|
224
|
+
universal: pct >= 80,
|
|
225
|
+
range: `${Math.round(Math.min(...failing))} ms–${Math.round(Math.max(...failing))} ms`,
|
|
226
|
+
threshold: `${spec.good} ms`,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const cwv_verdicts = { pass: 0, needs_improvement: 0, fail: 0 };
|
|
230
|
+
for (const run of runs)
|
|
231
|
+
cwv_verdicts[cwvVerdict(run)]++;
|
|
232
|
+
const tally = (verdict) => {
|
|
233
|
+
const counts = new Map();
|
|
234
|
+
for (const run of runs) {
|
|
235
|
+
for (const c of run.comparisons) {
|
|
236
|
+
if (c.verdict !== verdict)
|
|
237
|
+
continue;
|
|
238
|
+
counts.set(c.metric, (counts.get(c.metric) ?? 0) + 1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return [...counts.entries()]
|
|
242
|
+
.map(([metric, n]) => ({ metric, runs: n }))
|
|
243
|
+
.sort((a, b) => b.runs - a.runs);
|
|
244
|
+
};
|
|
245
|
+
// Outliers: a value far above the median for its own strategy. With
|
|
246
|
+
// runs_per_url = 1 there is nothing to check it against, so it is reported
|
|
247
|
+
// as unconfirmed rather than asserted — the manual report had to make this
|
|
248
|
+
// caveat in prose for its 9.97 s TBT reading.
|
|
249
|
+
const outliers = [];
|
|
250
|
+
for (const strategy of strategies) {
|
|
251
|
+
const group = runs.filter((r) => r.strategy === strategy);
|
|
252
|
+
for (const key of Object.keys(LAB_THRESHOLDS)) {
|
|
253
|
+
const values = group
|
|
254
|
+
.map((r) => r.lab[key])
|
|
255
|
+
.filter((v) => typeof v === "number");
|
|
256
|
+
if (values.length < 4)
|
|
257
|
+
continue;
|
|
258
|
+
const med = median(values);
|
|
259
|
+
if (med <= 0)
|
|
260
|
+
continue;
|
|
261
|
+
for (const run of group) {
|
|
262
|
+
const value = run.lab[key];
|
|
263
|
+
if (typeof value !== "number" || value / med < 3)
|
|
264
|
+
continue;
|
|
265
|
+
outliers.push({
|
|
266
|
+
url: run.url,
|
|
267
|
+
strategy,
|
|
268
|
+
metric: String(key),
|
|
269
|
+
value: `${Math.round(value)} ms`,
|
|
270
|
+
vs_median_multiple: Number((value / med).toFixed(1)),
|
|
271
|
+
confidence: run.runs > 1 ? `median_of_${run.runs}` : "unconfirmed_single_run",
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
run_count: runs.length,
|
|
278
|
+
pages: new Set(runs.map((r) => r.url)).size,
|
|
279
|
+
captured_at: new Date().toISOString(),
|
|
280
|
+
by_strategy,
|
|
281
|
+
by_template,
|
|
282
|
+
lab_metric_failures,
|
|
283
|
+
cwv_verdicts,
|
|
284
|
+
lab_vs_field_summary: {
|
|
285
|
+
worse_in_field: tally("worse_in_field"),
|
|
286
|
+
worse_in_lab: tally("worse_in_lab"),
|
|
287
|
+
confirmed: tally("confirmed"),
|
|
288
|
+
no_field_data: runs.filter((r) => !r.field).length,
|
|
289
|
+
},
|
|
290
|
+
outliers,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=psiAggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"psiAggregator.js","sourceRoot":"","sources":["../../src/mappers/psiAggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG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MAAM;SACnD;QACD,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Before-and-after comparison of two runs.
|
|
3
|
+
*
|
|
4
|
+
* A snapshot answers "what is wrong with this page". A developer about to open
|
|
5
|
+
* a PR has a different question: "did my fix work, and did I break anything?"
|
|
6
|
+
* Those are not the same question, and a count cannot distinguish them.
|
|
7
|
+
*
|
|
8
|
+
* Measured case, from a page where an `alt` attribute and an `aria-label` were
|
|
9
|
+
* added to fix a missing-alt-text blocker:
|
|
10
|
+
*
|
|
11
|
+
* before: 2 violations — image-alt (P1), color-contrast (P3)
|
|
12
|
+
* after: 2 violations — aria-valid-attr-value (P2), color-contrast (P3)
|
|
13
|
+
*
|
|
14
|
+
* Identical totals. The P1 was genuinely fixed, and the fix introduced a new
|
|
15
|
+
* defect, because the aria-labelledby it added pointed at an id that did not
|
|
16
|
+
* exist. Anyone reading "2 before, 2 after" concludes the change did nothing.
|
|
17
|
+
* `newly_introduced` is the half of this module that earns its keep.
|
|
18
|
+
*/
|
|
19
|
+
import type { Priority } from "../types.js";
|
|
20
|
+
/** One defect, identified the same way in both runs. */
|
|
21
|
+
export interface DefectRef {
|
|
22
|
+
url: string;
|
|
23
|
+
variant: string;
|
|
24
|
+
/** Rule code for accessibility, audit id for Lighthouse. */
|
|
25
|
+
id: string;
|
|
26
|
+
priority: Priority;
|
|
27
|
+
title?: string;
|
|
28
|
+
}
|
|
29
|
+
export type ComparisonVerdict = "clean" | "improved" | "mixed" | "regression" | "unchanged";
|
|
30
|
+
export interface ScoreChange {
|
|
31
|
+
url: string;
|
|
32
|
+
variant: string;
|
|
33
|
+
category: string;
|
|
34
|
+
before: number;
|
|
35
|
+
after: number;
|
|
36
|
+
delta: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ComparisonResult {
|
|
39
|
+
baseline_dir: string;
|
|
40
|
+
baseline_runs: number;
|
|
41
|
+
current_runs: number;
|
|
42
|
+
verdict: ComparisonVerdict;
|
|
43
|
+
summary: string;
|
|
44
|
+
fixed: Array<{
|
|
45
|
+
url: string;
|
|
46
|
+
variant: string;
|
|
47
|
+
id: string;
|
|
48
|
+
was: Priority;
|
|
49
|
+
title?: string;
|
|
50
|
+
}>;
|
|
51
|
+
still_failing: Array<{
|
|
52
|
+
url: string;
|
|
53
|
+
variant: string;
|
|
54
|
+
id: string;
|
|
55
|
+
priority: Priority;
|
|
56
|
+
title?: string;
|
|
57
|
+
}>;
|
|
58
|
+
newly_introduced: Array<{
|
|
59
|
+
url: string;
|
|
60
|
+
variant: string;
|
|
61
|
+
id: string;
|
|
62
|
+
priority: Priority;
|
|
63
|
+
title?: string;
|
|
64
|
+
}>;
|
|
65
|
+
score_changes?: ScoreChange[];
|
|
66
|
+
/** Runs present now but absent from the baseline — not comparable. */
|
|
67
|
+
not_in_baseline: string[];
|
|
68
|
+
/** Runs in the baseline that this run did not cover — silently uncompared otherwise. */
|
|
69
|
+
not_in_current: string[];
|
|
70
|
+
warnings: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compare two defect sets.
|
|
74
|
+
*
|
|
75
|
+
* Comparison is per (url, variant, defect id). A defect that moved priority
|
|
76
|
+
* between runs counts as still failing rather than as fixed-and-reintroduced,
|
|
77
|
+
* since it is the same defect on the same element — the priority shift shows up
|
|
78
|
+
* in `still_failing`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function compareRuns(baselineDir: string, baseline: DefectRef[], current: DefectRef[], options?: {
|
|
81
|
+
baselineRuns?: number;
|
|
82
|
+
currentRuns?: number;
|
|
83
|
+
baselineScores?: Map<string, Record<string, number>>;
|
|
84
|
+
currentScores?: Map<string, Record<string, number>>;
|
|
85
|
+
}): ComparisonResult;
|