@decocms/parity 0.35.35 → 0.35.36
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/AGENTS.md +1 -0
- package/CHANGELOG.md +8 -0
- package/dist/cli.js +618 -35
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -25,6 +25,7 @@ Do **not** run parity for:
|
|
|
25
25
|
| "is everything still working?" | `parity run --preset smoke` then `--preset full` if smoke is clean |
|
|
26
26
|
| "compare these two URLs in CI" | `parity journey --prod ... --cand ... --junit ... --github` |
|
|
27
27
|
| "find sections missing in the migration" | `parity run --visual-pages 5` then read `report.json` `.visualDiff` |
|
|
28
|
+
| "did my change just break a page that was fine?" (before each commit) | `parity gate --cand ... --dir <target>/.parity --only <pages>` (baseline once with `--update-baseline`; exit 1 = do not commit, 2 = could not judge; see `docs/cli.md`) |
|
|
28
29
|
| "did web vitals regress?" | `parity vitals --prod ... --cand ... --limit 20` |
|
|
29
30
|
| "is the new site missing cache?" | `parity cache --cand ... --limit 30` |
|
|
30
31
|
| "I want an LLM prompt with all the issues" | `parity prompt <runId>` (writes Markdown to stdout) |
|
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
+
* **`parity gate`: a fast pre-commit regression gate.** Loads each page x viewport once (one browser,
|
|
13
|
+
sequential, primed like `run`) and compares status, server HTML size, new section-crash / hydration /
|
|
14
|
+
uncaught errors, page height after the scroll, interactive element count, server-rendered
|
|
15
|
+
first-viewport sections and click-blocking overlays against `<dir>/gate-baseline.json`, a baseline of
|
|
16
|
+
the candidate itself. Exit 0 no regression with at least one page compared, 1 regression, 2 could not
|
|
17
|
+
judge (no baseline, cold or degraded candidate, nothing compared). `--update-baseline` accepts the
|
|
18
|
+
current state and refuses when a page is unjudgeable. `capturePage` gains an additive `lean` option
|
|
19
|
+
(skips vitals) and `PageCapture.gateProbe`; `fixer` and `porter` run the gate before every commit.
|
|
12
20
|
* **`parity run` notices a local candidate that degrades mid-run.** Priming records each URL's
|
|
13
21
|
status, document bytes and time; after the passes the same URLs are re-requested once, in order,
|
|
14
22
|
and compared (tolerances in `TOLERANCES.candHealth`). When the server is found degraded, a
|
package/dist/cli.js
CHANGED
|
@@ -75779,7 +75779,7 @@ import {
|
|
|
75779
75779
|
registerCommands as registerCatalogCommands
|
|
75780
75780
|
} from "@decocms/catalog";
|
|
75781
75781
|
import { DESCRIPTION, registerCommands } from "@decocms/vtex-cms";
|
|
75782
|
-
import
|
|
75782
|
+
import chalk51 from "chalk";
|
|
75783
75783
|
import { Command, InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
75784
75784
|
|
|
75785
75785
|
// src/commands/ab-detect.ts
|
|
@@ -83921,11 +83921,11 @@ ${compacted}
|
|
|
83921
83921
|
}
|
|
83922
83922
|
|
|
83923
83923
|
// src/engine/click-probe.ts
|
|
83924
|
+
var INTERACTIVE_SELECTOR = "a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button],[role=link],[role=menuitem],[role=tab],[onclick]";
|
|
83924
83925
|
var CLICK_PROBE_SOURCE = `(function (cols, rows, minPaintAlpha) {
|
|
83925
83926
|
var vw = window.innerWidth;
|
|
83926
83927
|
var vh = window.innerHeight;
|
|
83927
|
-
var INTERACTIVE =
|
|
83928
|
-
'a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button],[role=link],[role=menuitem],[role=tab],[onclick]';
|
|
83928
|
+
var INTERACTIVE = '${INTERACTIVE_SELECTOR}';
|
|
83929
83929
|
|
|
83930
83930
|
function describe(el) {
|
|
83931
83931
|
var s = el.tagName.toLowerCase();
|
|
@@ -84811,20 +84811,23 @@ async function reloadIfOptionalFonts(page, waitMs = 0) {
|
|
|
84811
84811
|
function formatSettleCaveat(side, settle) {
|
|
84812
84812
|
return settle.stable ? null : `${side}: layout still changing after ${settle.waitedMs}ms (height ${settle.heightPx}px) — measured anyway, so a large rect delta may be a timing artifact`;
|
|
84813
84813
|
}
|
|
84814
|
-
async function scrollFullPage(page, budgetMs = 45000) {
|
|
84814
|
+
async function scrollFullPage(page, budgetMs = 45000, quick = false) {
|
|
84815
84815
|
const start = Date.now();
|
|
84816
|
-
const
|
|
84816
|
+
const W = quick ? { step: 250, stableN: 2, stable: 300, bottom: 300, top: 100 } : { step: 400, stableN: 3, stable: 500, bottom: 1500, top: 700 };
|
|
84817
|
+
const result = await page.evaluate(async (a) => {
|
|
84818
|
+
const budget = a.budget;
|
|
84819
|
+
const w = a.w;
|
|
84817
84820
|
const SK = "[aria-busy='true'],[data-skeleton],[data-loading='true'],.skeleton,[class*='skeleton' i],[class*='Skeleton'],[class*='shimmer' i],.animate-pulse,.placeholder-shimmer,.react-loading-skeleton";
|
|
84818
84821
|
const innerStart = Date.now();
|
|
84819
84822
|
let y = 0;
|
|
84820
84823
|
let prevHeight = 0;
|
|
84821
84824
|
let stableTicks = 0;
|
|
84822
84825
|
let steps = 0;
|
|
84823
|
-
const STABLE_THRESHOLD =
|
|
84826
|
+
const STABLE_THRESHOLD = w.stableN;
|
|
84824
84827
|
while (budget - (Date.now() - innerStart) > 2000) {
|
|
84825
84828
|
window.scrollTo(0, y);
|
|
84826
84829
|
steps++;
|
|
84827
|
-
await new Promise((r) => setTimeout(r,
|
|
84830
|
+
await new Promise((r) => setTimeout(r, w.step));
|
|
84828
84831
|
const stepWaitStart = Date.now();
|
|
84829
84832
|
while (document.querySelectorAll(SK).length > 0 && Date.now() - stepWaitStart < 1500 && budget - (Date.now() - innerStart) > 1000) {
|
|
84830
84833
|
await new Promise((r) => setTimeout(r, 200));
|
|
@@ -84840,18 +84843,18 @@ async function scrollFullPage(page, budgetMs = 45000) {
|
|
|
84840
84843
|
stableTicks = 0;
|
|
84841
84844
|
prevHeight = height;
|
|
84842
84845
|
}
|
|
84843
|
-
await new Promise((r) => setTimeout(r,
|
|
84846
|
+
await new Promise((r) => setTimeout(r, w.stable));
|
|
84844
84847
|
} else {
|
|
84845
84848
|
y = Math.min(y + Math.max(viewport * 0.8, 600), height);
|
|
84846
84849
|
}
|
|
84847
84850
|
}
|
|
84848
84851
|
const finalHeight = document.documentElement.scrollHeight;
|
|
84849
84852
|
window.scrollTo(0, finalHeight);
|
|
84850
|
-
await new Promise((r) => setTimeout(r,
|
|
84853
|
+
await new Promise((r) => setTimeout(r, w.bottom));
|
|
84851
84854
|
window.scrollTo(0, 0);
|
|
84852
|
-
await new Promise((r) => setTimeout(r,
|
|
84855
|
+
await new Promise((r) => setTimeout(r, w.top));
|
|
84853
84856
|
return { steps, finalHeight, stableAtEnd: stableTicks >= STABLE_THRESHOLD };
|
|
84854
|
-
}, budgetMs);
|
|
84857
|
+
}, { budget: budgetMs, w: W });
|
|
84855
84858
|
return {
|
|
84856
84859
|
steps: result.steps,
|
|
84857
84860
|
finalHeight: result.finalHeight,
|
|
@@ -84918,6 +84921,7 @@ async function capturePage(page, opts) {
|
|
|
84918
84921
|
pairKey: opts.pairKey,
|
|
84919
84922
|
...clickProbe ? { clickProbe } : {},
|
|
84920
84923
|
...firstViewport ? { firstViewport } : {},
|
|
84924
|
+
...gateProbe ? { gateProbe } : {},
|
|
84921
84925
|
...response ? { variant: fingerprintVariant(html, response.headers(), cookieNames) } : {}
|
|
84922
84926
|
});
|
|
84923
84927
|
let cookieNames = [];
|
|
@@ -84929,8 +84933,11 @@ async function capturePage(page, opts) {
|
|
|
84929
84933
|
let vitalsFullPage = null;
|
|
84930
84934
|
let clickProbe;
|
|
84931
84935
|
let firstViewport;
|
|
84936
|
+
let gateProbe;
|
|
84932
84937
|
let html = "";
|
|
84933
84938
|
const readVitals = async () => {
|
|
84939
|
+
if (opts.lean)
|
|
84940
|
+
return null;
|
|
84934
84941
|
dlog(opts.side, opts.viewport, ` capturePage: vitals evaluate (cap=${Math.min(5000, remaining())}ms)`);
|
|
84935
84942
|
return await Promise.race([
|
|
84936
84943
|
page.evaluate(() => window.__parity_vitals).catch(() => null),
|
|
@@ -85003,7 +85010,7 @@ async function capturePage(page, opts) {
|
|
|
85003
85010
|
const scrollBudget = Math.min(45000, remaining());
|
|
85004
85011
|
dlog(opts.side, opts.viewport, ` capturePage: scrollFullPage start (budget=${scrollBudget}ms, remaining=${remaining()}ms)`);
|
|
85005
85012
|
const scrollResult = await Promise.race([
|
|
85006
|
-
scrollFullPage(page, scrollBudget).catch((err) => {
|
|
85013
|
+
scrollFullPage(page, scrollBudget, opts.lean).catch((err) => {
|
|
85007
85014
|
dlog(opts.side, opts.viewport, ` capturePage: scrollFullPage threw: ${err.message}`);
|
|
85008
85015
|
return;
|
|
85009
85016
|
}),
|
|
@@ -85020,7 +85027,7 @@ async function capturePage(page, opts) {
|
|
|
85020
85027
|
return;
|
|
85021
85028
|
});
|
|
85022
85029
|
}
|
|
85023
|
-
await page.waitForTimeout(Math.min(800, remaining()));
|
|
85030
|
+
await page.waitForTimeout(Math.min(opts.lean ? 200 : 800, remaining()));
|
|
85024
85031
|
vitalsFullPage = await readVitals();
|
|
85025
85032
|
}
|
|
85026
85033
|
}
|
|
@@ -85033,6 +85040,14 @@ async function capturePage(page, opts) {
|
|
|
85033
85040
|
if (vitals === null) {
|
|
85034
85041
|
vitals = await readVitals();
|
|
85035
85042
|
}
|
|
85043
|
+
if (opts.lean && response) {
|
|
85044
|
+
gateProbe = await Promise.race([
|
|
85045
|
+
page.evaluate(`({ pageHeight: document.documentElement.scrollHeight, interactive: document.querySelectorAll(${JSON.stringify(INTERACTIVE_SELECTOR)}).length })`).then((r) => r).catch(() => {
|
|
85046
|
+
return;
|
|
85047
|
+
}),
|
|
85048
|
+
new Promise((resolve) => setTimeout(() => resolve(undefined), Math.min(3000, remaining())))
|
|
85049
|
+
]);
|
|
85050
|
+
}
|
|
85036
85051
|
if (!opts.skipScreenshot) {
|
|
85037
85052
|
await Promise.race([
|
|
85038
85053
|
stabilizeCarousels(page).catch(() => {
|
|
@@ -91566,7 +91581,8 @@ var PageCapture = z2.object({
|
|
|
91566
91581
|
retried: z2.boolean().optional(),
|
|
91567
91582
|
candDegraded: z2.string().optional(),
|
|
91568
91583
|
clickProbe: ClickProbe.optional(),
|
|
91569
|
-
firstViewport: FirstViewportProbe.optional()
|
|
91584
|
+
firstViewport: FirstViewportProbe.optional(),
|
|
91585
|
+
gateProbe: z2.object({ pageHeight: z2.number(), interactive: z2.number() }).optional()
|
|
91570
91586
|
});
|
|
91571
91587
|
var StepCapture = z2.object({
|
|
91572
91588
|
step: z2.number(),
|
|
@@ -119873,6 +119889,9 @@ function markDegradedCaptures(candPages, baselines, recheck) {
|
|
|
119873
119889
|
}
|
|
119874
119890
|
return { degraded: true, marked };
|
|
119875
119891
|
}
|
|
119892
|
+
function watchesCandHealth(candBase) {
|
|
119893
|
+
return isLocalhost(candBase);
|
|
119894
|
+
}
|
|
119876
119895
|
async function recheckCand(urls, opts = {}) {
|
|
119877
119896
|
const out = new Map;
|
|
119878
119897
|
for (const url of urls) {
|
|
@@ -126102,8 +126121,569 @@ function driftCommand(flags) {
|
|
|
126102
126121
|
return r.commits > 0 ? 1 : 0;
|
|
126103
126122
|
}
|
|
126104
126123
|
|
|
126105
|
-
// src/commands/
|
|
126124
|
+
// src/commands/gate.ts
|
|
126125
|
+
import { existsSync as existsSync42, mkdirSync as mkdirSync26, readFileSync as readFileSync48, renameSync as renameSync4, writeFileSync as writeFileSync39 } from "node:fs";
|
|
126126
|
+
import { join as join55, resolve as resolve26 } from "node:path";
|
|
126106
126127
|
import chalk48 from "chalk";
|
|
126128
|
+
import { z as z7 } from "zod";
|
|
126129
|
+
|
|
126130
|
+
// src/commands/gate-tolerances.ts
|
|
126131
|
+
var GATE_TOLERANCES = {
|
|
126132
|
+
heightRel: {
|
|
126133
|
+
value: 0.05,
|
|
126134
|
+
unit: "ratio (0-1) of the baseline page height",
|
|
126135
|
+
basis: "assumed",
|
|
126136
|
+
note: "A page whose scroll height after the autoscroll moved by more than this share of its baseline height is changed. Lazy images and webfonts settle a page by a percent or two between two loads of the same code; a missing section or a crashed list moves it by tens of percent."
|
|
126137
|
+
},
|
|
126138
|
+
heightMinPx: {
|
|
126139
|
+
value: 100,
|
|
126140
|
+
unit: "px",
|
|
126141
|
+
basis: "assumed",
|
|
126142
|
+
note: "A height change under this is never reported, whatever the ratio: on a short page 5% is a few pixels, which a font swap or a carousel slide alone can produce. A section is rarely shorter than this."
|
|
126143
|
+
},
|
|
126144
|
+
interactiveDropRel: {
|
|
126145
|
+
value: 0.1,
|
|
126146
|
+
unit: "ratio (0-1) of the baseline element count",
|
|
126147
|
+
basis: "assumed",
|
|
126148
|
+
note: "The interactive element count (links, buttons, fields) falling by at least this share is a regression. Only a DROP counts: a page that gains elements (a new section, a hydrated shelf) is not broken."
|
|
126149
|
+
},
|
|
126150
|
+
interactiveDropMin: {
|
|
126151
|
+
value: 3,
|
|
126152
|
+
unit: "elements",
|
|
126153
|
+
basis: "assumed",
|
|
126154
|
+
note: "A drop smaller than this is never reported: on a small page one removed link is 10%. A section that disappears takes more than three links or buttons with it."
|
|
126155
|
+
},
|
|
126156
|
+
htmlCollapseRatio: {
|
|
126157
|
+
value: 0.5,
|
|
126158
|
+
unit: "ratio (0-1) of the baseline server HTML bytes",
|
|
126159
|
+
basis: "assumed",
|
|
126160
|
+
note: "A server document smaller than this share of the baseline's is a regression (a loader that now throws and renders its empty branch). Looser than candHealth.bytesCollapseRatio on purpose: that one says a SERVER is sick, this one says the CODE changed what it serves, and a changed page can legitimately shrink by a third."
|
|
126161
|
+
}
|
|
126162
|
+
};
|
|
126163
|
+
|
|
126164
|
+
// src/commands/gate.ts
|
|
126165
|
+
var gateKey = (path, viewport) => `${path}::${viewport}`;
|
|
126166
|
+
var is2xx = (s) => s !== null && s >= 200 && s < 300;
|
|
126167
|
+
var FORMAT_VERSION2 = 1;
|
|
126168
|
+
var BASELINE_FILE = "gate-baseline.json";
|
|
126169
|
+
var EntrySchema = z7.object({
|
|
126170
|
+
status: z7.number().nullable().default(null),
|
|
126171
|
+
htmlBytes: z7.number().nullable().default(null),
|
|
126172
|
+
errors: z7.array(z7.object({
|
|
126173
|
+
cls: z7.enum(["section-crash", "hydration", "uncaught"]),
|
|
126174
|
+
key: z7.string(),
|
|
126175
|
+
text: z7.string().default("")
|
|
126176
|
+
})).default([]),
|
|
126177
|
+
pageHeight: z7.number().nullable().default(null),
|
|
126178
|
+
interactive: z7.number().nullable().default(null),
|
|
126179
|
+
ssrSections: z7.array(z7.string()).nullable().default(null),
|
|
126180
|
+
deferredSections: z7.array(z7.string()).nullable().default(null),
|
|
126181
|
+
blockedShare: z7.number().nullable().default(null)
|
|
126182
|
+
});
|
|
126183
|
+
var BaselineSchema = z7.object({
|
|
126184
|
+
formatVersion: z7.number().default(FORMAT_VERSION2),
|
|
126185
|
+
recordedAt: z7.string().optional(),
|
|
126186
|
+
cand: z7.string().optional(),
|
|
126187
|
+
entries: z7.record(z7.string(), EntrySchema).default({})
|
|
126188
|
+
});
|
|
126189
|
+
function readBaseline(dir) {
|
|
126190
|
+
const file = join55(dir, BASELINE_FILE);
|
|
126191
|
+
if (!existsSync42(file))
|
|
126192
|
+
return { missing: true };
|
|
126193
|
+
try {
|
|
126194
|
+
const raw = JSON.parse(readFileSync48(file, "utf8"));
|
|
126195
|
+
if (typeof raw.formatVersion === "number" && raw.formatVersion > FORMAT_VERSION2) {
|
|
126196
|
+
return {
|
|
126197
|
+
error: `${file}: formatVersion ${raw.formatVersion} is newer than this parity reads (${FORMAT_VERSION2})`
|
|
126198
|
+
};
|
|
126199
|
+
}
|
|
126200
|
+
return { baseline: BaselineSchema.parse(raw) };
|
|
126201
|
+
} catch (err) {
|
|
126202
|
+
return { error: `${file}: ${err.message}` };
|
|
126203
|
+
}
|
|
126204
|
+
}
|
|
126205
|
+
function writeBaseline(dir, cand, entries, prior) {
|
|
126206
|
+
mkdirSync26(dir, { recursive: true });
|
|
126207
|
+
const file = join55(dir, BASELINE_FILE);
|
|
126208
|
+
const next = {
|
|
126209
|
+
formatVersion: FORMAT_VERSION2,
|
|
126210
|
+
recordedAt: new Date().toISOString(),
|
|
126211
|
+
cand,
|
|
126212
|
+
entries: { ...prior?.entries ?? {}, ...entries }
|
|
126213
|
+
};
|
|
126214
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
126215
|
+
writeFileSync39(tmp, `${JSON.stringify(next, null, 2)}
|
|
126216
|
+
`, "utf8");
|
|
126217
|
+
renameSync4(tmp, file);
|
|
126218
|
+
return file;
|
|
126219
|
+
}
|
|
126220
|
+
var MEASUREMENT_FAILURE2 = /^\[(capture-timeout|browser-disconnected|navigation-error)\]/;
|
|
126221
|
+
function urlOf(e) {
|
|
126222
|
+
const m = /https?:\/\/[^\s)]+/.exec(e.location ?? "");
|
|
126223
|
+
return m ? m[0] : null;
|
|
126224
|
+
}
|
|
126225
|
+
function isThirdParty3(e, pageUrl) {
|
|
126226
|
+
const u = urlOf(e);
|
|
126227
|
+
if (!u)
|
|
126228
|
+
return false;
|
|
126229
|
+
try {
|
|
126230
|
+
return registrableDomain(new URL(u).hostname) !== registrableDomain(new URL(pageUrl).hostname);
|
|
126231
|
+
} catch {
|
|
126232
|
+
return false;
|
|
126233
|
+
}
|
|
126234
|
+
}
|
|
126235
|
+
function gateErrors(entries, pageUrl, ignorePatterns = []) {
|
|
126236
|
+
const own = entries.filter((e) => !MEASUREMENT_FAILURE2.test(e.text) && !isThirdParty3(e, pageUrl));
|
|
126237
|
+
const out = new Map;
|
|
126238
|
+
for (const c of diffConsole(own, [], { ignorePatterns, errorsOnly: true }).prodErrors) {
|
|
126239
|
+
let cls = null;
|
|
126240
|
+
if (c.cls === "section-crash" || c.cls === "hydration")
|
|
126241
|
+
cls = c.cls;
|
|
126242
|
+
else if (c.cls === "generic" && (/^at\s/.test(c.entry.location ?? "") || /^Uncaught\b/.test(c.entry.text)))
|
|
126243
|
+
cls = "uncaught";
|
|
126244
|
+
if (!cls)
|
|
126245
|
+
continue;
|
|
126246
|
+
const section = cls === "section-crash" ? parseSectionCrash(c.entry.text).section : undefined;
|
|
126247
|
+
const key = `${cls}:${section ?? c.key.slice(0, 160)}`;
|
|
126248
|
+
if (!out.has(key))
|
|
126249
|
+
out.set(key, { cls, key, text: c.entry.text.slice(0, 200) });
|
|
126250
|
+
}
|
|
126251
|
+
return [...out.values()];
|
|
126252
|
+
}
|
|
126253
|
+
function docBytes(cap) {
|
|
126254
|
+
const docs = cap.network.filter((n) => n.resourceType === "document" && n.method === "GET");
|
|
126255
|
+
return (docs.find((n) => n.url === cap.url || n.url === cap.finalUrl) ?? docs[0])?.bytes ?? null;
|
|
126256
|
+
}
|
|
126257
|
+
function observe(path, viewport, cap, ctx) {
|
|
126258
|
+
const base = { key: gateKey(path, viewport), path, viewport };
|
|
126259
|
+
const no = (unjudged) => ({ ...base, entry: null, unjudged });
|
|
126260
|
+
if (ctx.cold)
|
|
126261
|
+
return no(ctx.cold);
|
|
126262
|
+
if (ctx.primeFailed)
|
|
126263
|
+
return no("the priming load never answered: the candidate is cold or down");
|
|
126264
|
+
if (!cap)
|
|
126265
|
+
return no("not captured");
|
|
126266
|
+
if (cap.candDegraded)
|
|
126267
|
+
return no(`candidate degraded: ${cap.candDegraded}`);
|
|
126268
|
+
if (cap.status === 0 && !ctx.primedOk) {
|
|
126269
|
+
return no("never answered, and nothing shows the server was up (a remote candidate is not primed)");
|
|
126270
|
+
}
|
|
126271
|
+
const fv = cap.firstViewport;
|
|
126272
|
+
const view = fv && fv.serverChars > 0 ? fv.sections.filter(inViewport) : null;
|
|
126273
|
+
const names = (ss) => ss ? [...new Set(ss.map((s) => s.name))] : null;
|
|
126274
|
+
const pts = cap.clickProbe?.points ?? [];
|
|
126275
|
+
return {
|
|
126276
|
+
...base,
|
|
126277
|
+
ms: cap.durationMs,
|
|
126278
|
+
entry: {
|
|
126279
|
+
status: cap.status,
|
|
126280
|
+
htmlBytes: docBytes(cap),
|
|
126281
|
+
errors: gateErrors(cap.console, cap.finalUrl || cap.url, ctx.ignorePatterns),
|
|
126282
|
+
pageHeight: cap.gateProbe?.pageHeight ?? null,
|
|
126283
|
+
interactive: cap.gateProbe?.interactive ?? null,
|
|
126284
|
+
ssrSections: names(view?.filter((s) => !isDeferred(s)) ?? null),
|
|
126285
|
+
deferredSections: names(view?.filter(isDeferred) ?? null),
|
|
126286
|
+
blockedShare: pts.length > 0 ? pts.filter(isBlocked).length / pts.length : null
|
|
126287
|
+
}
|
|
126288
|
+
};
|
|
126289
|
+
}
|
|
126290
|
+
var R = TOLERANCES.clickProbe.blockedShareMin.value;
|
|
126291
|
+
function judgeEntry(cur, b, prodHeight) {
|
|
126292
|
+
const bad = [];
|
|
126293
|
+
const good = [];
|
|
126294
|
+
const on = [];
|
|
126295
|
+
if (b.status !== null && cur.status !== null) {
|
|
126296
|
+
on.push("status");
|
|
126297
|
+
if (is2xx(b.status) && !is2xx(cur.status)) {
|
|
126298
|
+
bad.push(cur.status === 0 ? `no answer where the baseline answered ${b.status}` : `status ${b.status} -> ${cur.status}`);
|
|
126299
|
+
} else if (!is2xx(b.status) && is2xx(cur.status))
|
|
126300
|
+
good.push(`status ${b.status} -> ${cur.status}`);
|
|
126301
|
+
}
|
|
126302
|
+
on.push("errors");
|
|
126303
|
+
const had = new Set(b.errors.map((e) => e.key));
|
|
126304
|
+
const has = new Set(cur.errors.map((e) => e.key));
|
|
126305
|
+
for (const e of cur.errors) {
|
|
126306
|
+
if (!had.has(e.key))
|
|
126307
|
+
bad.push(`new ${e.cls}: ${e.key.slice(e.cls.length + 1) || e.text}`);
|
|
126308
|
+
}
|
|
126309
|
+
for (const e of b.errors)
|
|
126310
|
+
if (!has.has(e.key))
|
|
126311
|
+
good.push(`${e.cls} gone: ${e.key}`);
|
|
126312
|
+
if (b.htmlBytes && cur.htmlBytes !== null) {
|
|
126313
|
+
on.push("html-size");
|
|
126314
|
+
if (cur.htmlBytes < b.htmlBytes * GATE_TOLERANCES.htmlCollapseRatio.value) {
|
|
126315
|
+
bad.push(`server HTML ${kb2(b.htmlBytes)} -> ${kb2(cur.htmlBytes)}`);
|
|
126316
|
+
}
|
|
126317
|
+
}
|
|
126318
|
+
if (b.blockedShare !== null && cur.blockedShare !== null) {
|
|
126319
|
+
on.push("click-blockers");
|
|
126320
|
+
if (b.blockedShare < R && cur.blockedShare >= R) {
|
|
126321
|
+
bad.push(`an overlay now blocks ${Math.round(cur.blockedShare * 100)}% of the viewport's click points`);
|
|
126322
|
+
}
|
|
126323
|
+
}
|
|
126324
|
+
if (b.ssrSections && cur.deferredSections) {
|
|
126325
|
+
on.push("first-viewport");
|
|
126326
|
+
const lost = b.ssrSections.filter((n) => cur.deferredSections?.includes(n));
|
|
126327
|
+
if (lost.length)
|
|
126328
|
+
bad.push(`first-viewport section ${lost.join(", ")} was server-rendered, now deferred`);
|
|
126329
|
+
const won = (b.deferredSections ?? []).filter((n) => cur.ssrSections?.includes(n));
|
|
126330
|
+
if (won.length)
|
|
126331
|
+
good.push(`first-viewport section ${won.join(", ")} now server-rendered`);
|
|
126332
|
+
}
|
|
126333
|
+
if (b.interactive && cur.interactive !== null) {
|
|
126334
|
+
on.push("interactive");
|
|
126335
|
+
const drop = b.interactive - cur.interactive;
|
|
126336
|
+
if (drop >= GATE_TOLERANCES.interactiveDropMin.value && drop / b.interactive >= GATE_TOLERANCES.interactiveDropRel.value) {
|
|
126337
|
+
bad.push(`interactive elements ${b.interactive} -> ${cur.interactive}`);
|
|
126338
|
+
}
|
|
126339
|
+
}
|
|
126340
|
+
if (b.pageHeight && cur.pageHeight !== null) {
|
|
126341
|
+
on.push("height");
|
|
126342
|
+
const delta = cur.pageHeight - b.pageHeight;
|
|
126343
|
+
if (Math.abs(delta) >= GATE_TOLERANCES.heightMinPx.value && Math.abs(delta) / b.pageHeight > GATE_TOLERANCES.heightRel.value) {
|
|
126344
|
+
const text = `page height ${Math.round(b.pageHeight)} -> ${Math.round(cur.pageHeight)} px (${delta > 0 ? "+" : ""}${Math.round(delta)})`;
|
|
126345
|
+
if (prodHeight === undefined)
|
|
126346
|
+
bad.push(text);
|
|
126347
|
+
else if (Math.abs(cur.pageHeight - prodHeight) > Math.abs(b.pageHeight - prodHeight))
|
|
126348
|
+
bad.push(`${text}, away from prod's ${Math.round(prodHeight)}`);
|
|
126349
|
+
else
|
|
126350
|
+
good.push(`${text}, toward prod's ${Math.round(prodHeight)}`);
|
|
126351
|
+
}
|
|
126352
|
+
}
|
|
126353
|
+
return { bad, good, judgedOn: on };
|
|
126354
|
+
}
|
|
126355
|
+
var kb2 = (n) => `${Math.round(n / 1024)} KB`;
|
|
126356
|
+
function judgeGate(input) {
|
|
126357
|
+
const { baseline } = input;
|
|
126358
|
+
const cells = input.observations.map((o) => {
|
|
126359
|
+
const cell = {
|
|
126360
|
+
key: o.key,
|
|
126361
|
+
page: o.path,
|
|
126362
|
+
viewport: o.viewport,
|
|
126363
|
+
...o.ms !== undefined ? { ms: o.ms } : {}
|
|
126364
|
+
};
|
|
126365
|
+
if (!o.entry) {
|
|
126366
|
+
const reason = o.unjudged ?? "not judged";
|
|
126367
|
+
return {
|
|
126368
|
+
...cell,
|
|
126369
|
+
verdict: "inconclusive",
|
|
126370
|
+
reason,
|
|
126371
|
+
reasons: [reason],
|
|
126372
|
+
baselined: false,
|
|
126373
|
+
judgedOn: []
|
|
126374
|
+
};
|
|
126375
|
+
}
|
|
126376
|
+
const b = baseline?.entries[o.key];
|
|
126377
|
+
if (!b) {
|
|
126378
|
+
const bad = [];
|
|
126379
|
+
if (!is2xx(o.entry.status))
|
|
126380
|
+
bad.push(`new page answers ${o.entry.status} (no baseline)`);
|
|
126381
|
+
for (const e of o.entry.errors.filter((x) => x.cls === "section-crash"))
|
|
126382
|
+
bad.push(`new page: section-crash ${e.key.slice("section-crash:".length)} (no baseline)`);
|
|
126383
|
+
return bad.length ? {
|
|
126384
|
+
...cell,
|
|
126385
|
+
verdict: "regressed",
|
|
126386
|
+
reason: bad[0],
|
|
126387
|
+
reasons: bad,
|
|
126388
|
+
baselined: false,
|
|
126389
|
+
judgedOn: ["status", "section-crash"]
|
|
126390
|
+
} : {
|
|
126391
|
+
...cell,
|
|
126392
|
+
verdict: "new",
|
|
126393
|
+
reason: "no baseline entry for this page",
|
|
126394
|
+
reasons: ["no baseline entry for this page"],
|
|
126395
|
+
baselined: false,
|
|
126396
|
+
judgedOn: ["status", "section-crash"]
|
|
126397
|
+
};
|
|
126398
|
+
}
|
|
126399
|
+
const { bad, good, judgedOn } = judgeEntry(o.entry, b, input.goldenHeights?.[o.key]);
|
|
126400
|
+
if (bad.length)
|
|
126401
|
+
return {
|
|
126402
|
+
...cell,
|
|
126403
|
+
verdict: "regressed",
|
|
126404
|
+
reason: bad[0],
|
|
126405
|
+
reasons: bad,
|
|
126406
|
+
baselined: true,
|
|
126407
|
+
judgedOn
|
|
126408
|
+
};
|
|
126409
|
+
if (good.length)
|
|
126410
|
+
return {
|
|
126411
|
+
...cell,
|
|
126412
|
+
verdict: "improved",
|
|
126413
|
+
reason: good[0],
|
|
126414
|
+
reasons: good,
|
|
126415
|
+
baselined: true,
|
|
126416
|
+
judgedOn
|
|
126417
|
+
};
|
|
126418
|
+
return {
|
|
126419
|
+
...cell,
|
|
126420
|
+
verdict: "unchanged",
|
|
126421
|
+
reason: "same as baseline",
|
|
126422
|
+
reasons: [],
|
|
126423
|
+
baselined: true,
|
|
126424
|
+
judgedOn
|
|
126425
|
+
};
|
|
126426
|
+
});
|
|
126427
|
+
const n = (v) => cells.filter((c) => c.verdict === v).length;
|
|
126428
|
+
const counts = {
|
|
126429
|
+
compared: cells.filter((c) => c.baselined).length,
|
|
126430
|
+
unchanged: n("unchanged"),
|
|
126431
|
+
improved: n("improved"),
|
|
126432
|
+
regressed: n("regressed"),
|
|
126433
|
+
new: n("new"),
|
|
126434
|
+
inconclusive: n("inconclusive")
|
|
126435
|
+
};
|
|
126436
|
+
const parts = [`${counts.compared} compared`, `${counts.unchanged} unchanged`];
|
|
126437
|
+
if (counts.improved)
|
|
126438
|
+
parts.push(`${counts.improved} improved`);
|
|
126439
|
+
parts.push(`${counts.regressed} regressed`);
|
|
126440
|
+
if (counts.new)
|
|
126441
|
+
parts.push(`${counts.new} new (no baseline)`);
|
|
126442
|
+
if (counts.inconclusive)
|
|
126443
|
+
parts.push(`${counts.inconclusive} inconclusive`);
|
|
126444
|
+
let exit;
|
|
126445
|
+
let summary = parts.join(", ");
|
|
126446
|
+
if (counts.regressed > 0)
|
|
126447
|
+
exit = 1;
|
|
126448
|
+
else if (counts.compared === 0) {
|
|
126449
|
+
exit = 2;
|
|
126450
|
+
summary = `nothing compared: ${cells.length === 0 ? "no pages" : baseline === null ? "no baseline" : counts.inconclusive === cells.length ? "every page was inconclusive" : "no page has a baseline entry"} (${parts.join(", ")})`;
|
|
126451
|
+
} else if (counts.inconclusive > 0) {
|
|
126452
|
+
exit = 2;
|
|
126453
|
+
summary += `: ${counts.inconclusive} page(s) could not be judged, treat them as unverified`;
|
|
126454
|
+
} else
|
|
126455
|
+
exit = 0;
|
|
126456
|
+
return { cells, counts, summary, exit };
|
|
126457
|
+
}
|
|
126458
|
+
function updateRefusal(observations) {
|
|
126459
|
+
if (observations.length === 0)
|
|
126460
|
+
return ["no pages were observed"];
|
|
126461
|
+
return observations.filter((o) => !o.entry).map((o) => `${o.key}: ${o.unjudged ?? "not judged"}`);
|
|
126462
|
+
}
|
|
126463
|
+
var pathAndQuery2 = (url) => {
|
|
126464
|
+
try {
|
|
126465
|
+
const u = new URL(url);
|
|
126466
|
+
return (u.pathname || "/") + u.search;
|
|
126467
|
+
} catch {
|
|
126468
|
+
return url;
|
|
126469
|
+
}
|
|
126470
|
+
};
|
|
126471
|
+
function goldenPages(dir) {
|
|
126472
|
+
const g = loadGolden(dir);
|
|
126473
|
+
if ("error" in g)
|
|
126474
|
+
return g;
|
|
126475
|
+
const { prodPages, candPages } = g.rec.ctx;
|
|
126476
|
+
const idOf = (p) => p.pairKey ?? pathAndQuery2(p.url);
|
|
126477
|
+
const pages = [];
|
|
126478
|
+
const heights = {};
|
|
126479
|
+
for (const c of candPages.filter((p) => p.pass === "visual")) {
|
|
126480
|
+
const path = pathAndQuery2(c.url);
|
|
126481
|
+
if (!pages.includes(path))
|
|
126482
|
+
pages.push(path);
|
|
126483
|
+
const prod = prodPages.find((p) => p.pass === "visual" && p.viewport === c.viewport && idOf(p) === idOf(c));
|
|
126484
|
+
const px = prod ? readPngSize(prod.screenshotPath)?.height : undefined;
|
|
126485
|
+
if (px)
|
|
126486
|
+
heights[gateKey(path, c.viewport)] = px / (VIEWPORT_PRESETS[c.viewport].deviceScaleFactor ?? 1);
|
|
126487
|
+
}
|
|
126488
|
+
return { pages, heights };
|
|
126489
|
+
}
|
|
126490
|
+
async function captureGate(cand, paths, viewports) {
|
|
126491
|
+
const browser = await launchBrowser({ headless: true });
|
|
126492
|
+
const ignorePatterns = loadParityIgnore().ignoreConsolePatterns;
|
|
126493
|
+
const urlOf = (p) => new URL(p, cand).toString();
|
|
126494
|
+
try {
|
|
126495
|
+
const t0 = Date.now();
|
|
126496
|
+
const baselines = new Map;
|
|
126497
|
+
const primeUrls = planCandPrime(cand, paths.map(urlOf), new Set);
|
|
126498
|
+
const primed = new Set;
|
|
126499
|
+
const prime = await primeCandUrls(browser, primeUrls, primed, { viewport: viewports[0] }, baselines);
|
|
126500
|
+
const primeFailed = new Set(prime.failed);
|
|
126501
|
+
const cold = isColdCandidate({ total: prime.attempted, failed: prime.failed.length }) ? `the candidate is cold: ${prime.failed.length} of ${prime.attempted} priming loads never answered` : undefined;
|
|
126502
|
+
const primeMs = Date.now() - t0;
|
|
126503
|
+
const caps = new Map;
|
|
126504
|
+
const t1 = Date.now();
|
|
126505
|
+
if (!cold) {
|
|
126506
|
+
for (const viewport of viewports) {
|
|
126507
|
+
const ctx = await newContext(browser, { viewport, cohortCookieValue: "control" });
|
|
126508
|
+
try {
|
|
126509
|
+
for (const path of paths) {
|
|
126510
|
+
const url = urlOf(path);
|
|
126511
|
+
if (primeFailed.has(url))
|
|
126512
|
+
continue;
|
|
126513
|
+
const page = await ctx.newPage();
|
|
126514
|
+
try {
|
|
126515
|
+
const cap = await capturePage(page, {
|
|
126516
|
+
url,
|
|
126517
|
+
side: "cand",
|
|
126518
|
+
viewport,
|
|
126519
|
+
screenshotPath: "",
|
|
126520
|
+
settleMs: 800,
|
|
126521
|
+
timeoutMs: 20000,
|
|
126522
|
+
skipScreenshot: true,
|
|
126523
|
+
noNetworkIdle: true,
|
|
126524
|
+
lean: true
|
|
126525
|
+
});
|
|
126526
|
+
caps.set(gateKey(path, viewport), cap);
|
|
126527
|
+
} catch {} finally {
|
|
126528
|
+
await page.close().catch(() => {
|
|
126529
|
+
return;
|
|
126530
|
+
});
|
|
126531
|
+
}
|
|
126532
|
+
}
|
|
126533
|
+
} finally {
|
|
126534
|
+
await ctx.close().catch(() => {
|
|
126535
|
+
return;
|
|
126536
|
+
});
|
|
126537
|
+
}
|
|
126538
|
+
}
|
|
126539
|
+
}
|
|
126540
|
+
const captureMs = Date.now() - t1;
|
|
126541
|
+
let degraded = false;
|
|
126542
|
+
if (!cold && watchesCandHealth(cand)) {
|
|
126543
|
+
const after = await recheckCand([...baselines.keys()]);
|
|
126544
|
+
degraded = markDegradedCaptures([...caps.values()], baselines, judgeRecheck(baselines, after)).degraded;
|
|
126545
|
+
}
|
|
126546
|
+
const observations = viewports.flatMap((viewport) => paths.map((path) => observe(path, viewport, caps.get(gateKey(path, viewport)), {
|
|
126547
|
+
candUrl: cand,
|
|
126548
|
+
cold,
|
|
126549
|
+
primeFailed: primeFailed.has(urlOf(path)),
|
|
126550
|
+
primedOk: baselines.has(urlOf(path)),
|
|
126551
|
+
ignorePatterns
|
|
126552
|
+
})));
|
|
126553
|
+
return { observations, primeMs, captureMs, degraded };
|
|
126554
|
+
} finally {
|
|
126555
|
+
await browser.close().catch(() => {
|
|
126556
|
+
return;
|
|
126557
|
+
});
|
|
126558
|
+
}
|
|
126559
|
+
}
|
|
126560
|
+
function fail4(flags, code, message) {
|
|
126561
|
+
if (flags.json)
|
|
126562
|
+
console.log(JSON.stringify({ exit: 2, error: { code, message } }));
|
|
126563
|
+
else
|
|
126564
|
+
console.error(chalk48.red(` gate: ${message}`));
|
|
126565
|
+
return 2;
|
|
126566
|
+
}
|
|
126567
|
+
var normalize4 = (p) => p.startsWith("/") ? p : `/${p}`;
|
|
126568
|
+
async function gateCommand(flags, deps = { capture: captureGate }) {
|
|
126569
|
+
if (!flags.cand)
|
|
126570
|
+
return fail4(flags, "no_cand", "--cand <url> is required");
|
|
126571
|
+
try {
|
|
126572
|
+
new URL(flags.cand);
|
|
126573
|
+
} catch {
|
|
126574
|
+
return fail4(flags, "bad_cand", `--cand "${flags.cand}" is not a URL`);
|
|
126575
|
+
}
|
|
126576
|
+
const viewports = [];
|
|
126577
|
+
for (const v of (flags.viewports ?? "mobile,desktop").split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
126578
|
+
const r = Viewport.safeParse(v);
|
|
126579
|
+
if (!r.success)
|
|
126580
|
+
return fail4(flags, "bad_viewport", `--viewports: "${v}" is not mobile, tablet or desktop`);
|
|
126581
|
+
if (!viewports.includes(r.data))
|
|
126582
|
+
viewports.push(r.data);
|
|
126583
|
+
}
|
|
126584
|
+
if (viewports.length === 0)
|
|
126585
|
+
return fail4(flags, "bad_viewport", "--viewports is empty");
|
|
126586
|
+
const dir = resolve26(flags.dir ?? ".parity");
|
|
126587
|
+
const read = readBaseline(dir);
|
|
126588
|
+
if ("error" in read)
|
|
126589
|
+
return fail4(flags, "baseline_unreadable", read.error);
|
|
126590
|
+
const baseline = "baseline" in read ? read.baseline : null;
|
|
126591
|
+
if (!baseline && !flags.updateBaseline) {
|
|
126592
|
+
return fail4(flags, "no_baseline", `nothing compared: no baseline at ${join55(dir, BASELINE_FILE)}. Run once with --update-baseline on a state known to be good.`);
|
|
126593
|
+
}
|
|
126594
|
+
let paths = null;
|
|
126595
|
+
let heights;
|
|
126596
|
+
try {
|
|
126597
|
+
const explicit = resolveExplicitPages(flags.pagesFile, flags.pages);
|
|
126598
|
+
if (explicit)
|
|
126599
|
+
paths = explicit.map((p) => normalize4(p.cand));
|
|
126600
|
+
} catch (err) {
|
|
126601
|
+
return fail4(flags, "bad_pages", err.message);
|
|
126602
|
+
}
|
|
126603
|
+
if (flags.golden) {
|
|
126604
|
+
const g = goldenPages(flags.golden);
|
|
126605
|
+
if ("error" in g)
|
|
126606
|
+
return fail4(flags, "bad_golden", g.error);
|
|
126607
|
+
paths ??= g.pages;
|
|
126608
|
+
heights = g.heights;
|
|
126609
|
+
}
|
|
126610
|
+
const only = flags.only ? parsePageList(flags.only, { fallback: [] }).map(normalize4) : null;
|
|
126611
|
+
if (!paths && baseline) {
|
|
126612
|
+
paths = [...new Set(Object.keys(baseline.entries).map((k) => k.slice(0, k.lastIndexOf("::"))))];
|
|
126613
|
+
if (only)
|
|
126614
|
+
paths = only;
|
|
126615
|
+
} else if (paths && only) {
|
|
126616
|
+
paths = paths.filter((p) => only.includes(p));
|
|
126617
|
+
}
|
|
126618
|
+
if (!paths || paths.length === 0) {
|
|
126619
|
+
return fail4(flags, "no_pages", only ? "--only matched none of the pages" : "no pages: pass --pages, --pages-file or --golden");
|
|
126620
|
+
}
|
|
126621
|
+
paths = [...new Set(paths)];
|
|
126622
|
+
const cap = await deps.capture(flags.cand, paths, viewports).catch((err) => err);
|
|
126623
|
+
if (cap instanceof Error)
|
|
126624
|
+
return fail4(flags, "capture_failed", cap.message);
|
|
126625
|
+
if (flags.updateBaseline) {
|
|
126626
|
+
const why = updateRefusal(cap.observations);
|
|
126627
|
+
if (why.length > 0) {
|
|
126628
|
+
if (flags.json)
|
|
126629
|
+
console.log(JSON.stringify({ exit: 2, baselineWritten: false, refused: why }));
|
|
126630
|
+
else {
|
|
126631
|
+
console.error(chalk48.red(" gate: baseline NOT written, these pages could not be judged:"));
|
|
126632
|
+
for (const w of why)
|
|
126633
|
+
console.error(chalk48.red(` ${w}`));
|
|
126634
|
+
}
|
|
126635
|
+
return 2;
|
|
126636
|
+
}
|
|
126637
|
+
const entries = Object.fromEntries(cap.observations.map((o) => [o.key, o.entry]));
|
|
126638
|
+
const file = writeBaseline(dir, flags.cand, entries, baseline);
|
|
126639
|
+
const broken = cap.observations.filter((o) => o.entry && (!is2xx(o.entry.status) || o.entry.errors.length > 0));
|
|
126640
|
+
if (flags.json) {
|
|
126641
|
+
console.log(JSON.stringify({
|
|
126642
|
+
exit: 0,
|
|
126643
|
+
baselineWritten: true,
|
|
126644
|
+
file,
|
|
126645
|
+
pages: cap.observations.length,
|
|
126646
|
+
withDefects: broken.map((o) => o.key)
|
|
126647
|
+
}));
|
|
126648
|
+
} else {
|
|
126649
|
+
console.log(chalk48.green(` baseline written: ${cap.observations.length} page x viewport -> ${file}`));
|
|
126650
|
+
for (const o of broken) {
|
|
126651
|
+
console.log(chalk48.yellow(` ! ${o.key} was recorded WITH a defect (status ${o.entry?.status}, ${o.entry?.errors.length} error(s)): future runs will treat it as accepted`));
|
|
126652
|
+
}
|
|
126653
|
+
}
|
|
126654
|
+
return 0;
|
|
126655
|
+
}
|
|
126656
|
+
const report = judgeGate({ observations: cap.observations, baseline, goldenHeights: heights });
|
|
126657
|
+
if (flags.json) {
|
|
126658
|
+
console.log(JSON.stringify({
|
|
126659
|
+
exit: report.exit,
|
|
126660
|
+
summary: report.summary,
|
|
126661
|
+
counts: report.counts,
|
|
126662
|
+
cells: report.cells,
|
|
126663
|
+
degraded: cap.degraded,
|
|
126664
|
+
timing: { primeMs: cap.primeMs, captureMs: cap.captureMs }
|
|
126665
|
+
}));
|
|
126666
|
+
} else {
|
|
126667
|
+
for (const c of report.cells) {
|
|
126668
|
+
const mark = {
|
|
126669
|
+
regressed: chalk48.red("REGRESSED "),
|
|
126670
|
+
improved: chalk48.green("improved "),
|
|
126671
|
+
unchanged: chalk48.dim("unchanged "),
|
|
126672
|
+
new: chalk48.yellow("new "),
|
|
126673
|
+
inconclusive: chalk48.yellow("inconclusive")
|
|
126674
|
+
}[c.verdict];
|
|
126675
|
+
const ms = c.ms !== undefined ? chalk48.dim(` ${(c.ms / 1000).toFixed(1)}s`) : "";
|
|
126676
|
+
console.log(` ${mark} ${c.page} [${c.viewport}] ${c.verdict === "unchanged" ? "" : c.reason}${ms}`);
|
|
126677
|
+
}
|
|
126678
|
+
const color = report.exit === 0 ? chalk48.green : report.exit === 1 ? chalk48.red : chalk48.yellow;
|
|
126679
|
+
console.log(color(` ${report.summary}`));
|
|
126680
|
+
console.log(chalk48.dim(` prime ${(cap.primeMs / 1000).toFixed(1)}s, capture ${(cap.captureMs / 1000).toFixed(1)}s`));
|
|
126681
|
+
}
|
|
126682
|
+
return report.exit;
|
|
126683
|
+
}
|
|
126684
|
+
|
|
126685
|
+
// src/commands/variance.ts
|
|
126686
|
+
import chalk49 from "chalk";
|
|
126107
126687
|
|
|
126108
126688
|
// src/diff/variance.ts
|
|
126109
126689
|
var uniq2 = (xs) => [...new Set(xs)];
|
|
@@ -126207,7 +126787,7 @@ function formatVariance(report, opts = {}) {
|
|
|
126207
126787
|
// src/commands/variance.ts
|
|
126208
126788
|
function varianceCommand(opts) {
|
|
126209
126789
|
if (opts.runIds.length < 2) {
|
|
126210
|
-
console.error(
|
|
126790
|
+
console.error(chalk49.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
|
|
126211
126791
|
return 2;
|
|
126212
126792
|
}
|
|
126213
126793
|
const budget = Number.parseFloat(opts.scoreBudget ?? "1");
|
|
@@ -126216,7 +126796,7 @@ function varianceCommand(opts) {
|
|
|
126216
126796
|
try {
|
|
126217
126797
|
runs.push(loadRun(opts.output, id));
|
|
126218
126798
|
} catch (err) {
|
|
126219
|
-
console.error(
|
|
126799
|
+
console.error(chalk49.red(` ✖ ${err.message}`));
|
|
126220
126800
|
return 2;
|
|
126221
126801
|
}
|
|
126222
126802
|
}
|
|
@@ -126225,7 +126805,7 @@ function varianceCommand(opts) {
|
|
|
126225
126805
|
console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
|
|
126226
126806
|
} else {
|
|
126227
126807
|
console.log("");
|
|
126228
|
-
console.log(
|
|
126808
|
+
console.log(chalk49.bold(" Score variance"));
|
|
126229
126809
|
for (const line of formatVariance(report, { scoreBudget: budget }).split(`
|
|
126230
126810
|
`)) {
|
|
126231
126811
|
console.log(` ${line}`);
|
|
@@ -126237,10 +126817,10 @@ function varianceCommand(opts) {
|
|
|
126237
126817
|
}
|
|
126238
126818
|
|
|
126239
126819
|
// src/commands/vitals.ts
|
|
126240
|
-
import { existsSync as
|
|
126820
|
+
import { existsSync as existsSync43, readFileSync as readFileSync49, writeFileSync as writeFileSync40 } from "node:fs";
|
|
126241
126821
|
import { availableParallelism } from "node:os";
|
|
126242
|
-
import { join as
|
|
126243
|
-
import
|
|
126822
|
+
import { join as join56 } from "node:path";
|
|
126823
|
+
import chalk50 from "chalk";
|
|
126244
126824
|
import ora9 from "ora";
|
|
126245
126825
|
|
|
126246
126826
|
// src/checks/agentic-nav.ts
|
|
@@ -126548,10 +127128,10 @@ async function vitalsCommand(opts) {
|
|
|
126548
127128
|
const runId = newRunId();
|
|
126549
127129
|
const paths = createRunDir(opts.output, runId);
|
|
126550
127130
|
const t0 = Date.now();
|
|
126551
|
-
console.log(
|
|
127131
|
+
console.log(chalk50.bold(`
|
|
126552
127132
|
parity vitals ${runId}`));
|
|
126553
|
-
console.log(
|
|
126554
|
-
console.log(
|
|
127133
|
+
console.log(chalk50.dim(` prod: ${opts.prod}`));
|
|
127134
|
+
console.log(chalk50.dim(` cand: ${opts.cand}`));
|
|
126555
127135
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
126556
127136
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
126557
127137
|
if (pagePaths.length === 0) {
|
|
@@ -126583,12 +127163,12 @@ async function vitalsCommand(opts) {
|
|
|
126583
127163
|
completed++;
|
|
126584
127164
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
126585
127165
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
126586
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
127166
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk50.cyan("prod") : chalk50.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
126587
127167
|
}
|
|
126588
127168
|
});
|
|
126589
127169
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
126590
127170
|
if (opts.lighthouse !== false) {
|
|
126591
|
-
const lhDir =
|
|
127171
|
+
const lhDir = join56(paths.runDir, "lighthouse");
|
|
126592
127172
|
const lhCap = opts.lighthouseConcurrency ?? Math.max(1, Math.min(2, Math.floor(availableParallelism() / 2)));
|
|
126593
127173
|
const done = tasks.filter((t) => !!t.capture);
|
|
126594
127174
|
const lhT0 = Date.now();
|
|
@@ -126612,7 +127192,7 @@ async function vitalsCommand(opts) {
|
|
|
126612
127192
|
}
|
|
126613
127193
|
lhCompleted++;
|
|
126614
127194
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
126615
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
127195
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk50.cyan("prod") : chalk50.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
126616
127196
|
});
|
|
126617
127197
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
126618
127198
|
}
|
|
@@ -126677,7 +127257,7 @@ async function vitalsCommand(opts) {
|
|
|
126677
127257
|
writeRunReportJson(paths.runDir, run);
|
|
126678
127258
|
const html = renderHtmlReport(run, paths.runDir);
|
|
126679
127259
|
writeRunReportHtml(paths.runDir, html);
|
|
126680
|
-
|
|
127260
|
+
writeFileSync40(join56(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
126681
127261
|
schemaVersion: "0.1",
|
|
126682
127262
|
prodUrl: opts.prod,
|
|
126683
127263
|
candUrl: opts.cand,
|
|
@@ -126690,8 +127270,8 @@ async function vitalsCommand(opts) {
|
|
|
126690
127270
|
`, "utf8");
|
|
126691
127271
|
printSummary9(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
126692
127272
|
console.log("");
|
|
126693
|
-
console.log(
|
|
126694
|
-
console.log(
|
|
127273
|
+
console.log(chalk50.dim(` → ${paths.reportHtml}`));
|
|
127274
|
+
console.log(chalk50.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
126695
127275
|
console.log("");
|
|
126696
127276
|
if (opts.open) {
|
|
126697
127277
|
const { default: open } = await import("open");
|
|
@@ -126783,15 +127363,15 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
126783
127363
|
function parseUrlList(input) {
|
|
126784
127364
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
126785
127365
|
const path = input.replace(/^file:\/\//, "");
|
|
126786
|
-
if (
|
|
126787
|
-
return
|
|
127366
|
+
if (existsSync43(path)) {
|
|
127367
|
+
return readFileSync49(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
126788
127368
|
}
|
|
126789
127369
|
}
|
|
126790
127370
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
126791
127371
|
}
|
|
126792
127372
|
function printSummary9(vitals, cache, scores, opportunities, agentic) {
|
|
126793
127373
|
console.log("");
|
|
126794
|
-
console.log(
|
|
127374
|
+
console.log(chalk50.bold(" Summary:"));
|
|
126795
127375
|
console.log(` ${vitals.summary}`);
|
|
126796
127376
|
console.log(` ${cache.summary}`);
|
|
126797
127377
|
if (scores.status !== "skipped")
|
|
@@ -126855,10 +127435,10 @@ sweep.addCommand(new Command("regress").description("Run only the store's tests/
|
|
|
126855
127435
|
if (opts.json)
|
|
126856
127436
|
console.log(JSON.stringify({ url: opts.url, issues }));
|
|
126857
127437
|
else if (!issues.length)
|
|
126858
|
-
console.log(
|
|
127438
|
+
console.log(chalk51.green(" regression suite: all passed"));
|
|
126859
127439
|
else
|
|
126860
127440
|
for (const i of issues)
|
|
126861
|
-
console.log((i.inconclusive ?
|
|
127441
|
+
console.log((i.inconclusive ? chalk51.yellow : chalk51.red)(` ${i.summary}`));
|
|
126862
127442
|
process.exit(regressed ? 1 : unverified ? 2 : 0);
|
|
126863
127443
|
}));
|
|
126864
127444
|
sweep.addCommand(new Command("file").description("File an existing sweep run's findings on the Studio board (default: the newest sweep run). Merges <run>/sweeper-issues.json written by the `sweeper` agent. Dry run unless --yes.").option("--run <runId>", "Sweep run id (default: newest sweep in --output)").option("--output <dir>", "Output directory", "./parity-output").option("--board <name>", "Board: studio", "studio").option("--yes", "Actually create/update cards", false).option("--allow-automation", "File even if the board's triage column starts an agent", false).option("--min-severity <sev>", "critical|high|medium|low", "medium").option("--repo <owner/name>", "Repository to put on the cards").option("--artifacts-url <url>", "Public base URL for this run's artifacts").option("--json", "Emit JSON", false).action(async (opts) => {
|
|
@@ -127215,6 +127795,9 @@ program.command("drift").description("How far has the SOURCE repo moved since th
|
|
|
127215
127795
|
program.command("capacity").description("May one more heavy agent (dev server + headless Chromium + a gate run) start on this machine now, and how many more? Measures cores, 1-minute load, available memory, swap and free disk, then slots = min(--max, memory, cpu, swap, disk) floored at 0. The load already includes running agents, so --running is echoed, never subtracted: re-run before each start. Read-only. Exits 0 admit, 1 no headroom, 2 could not measure enough to decide (an unreadable input caps at 1, never counts as headroom).").option("--dir <path>", "Directory whose volume's free disk is measured", ".").option("--running <n>", "Agents the caller already has running (echoed back; not subtracted)").option("--max <n>", "Ceiling on parallel agents (default 5)").option("--per-agent-gb <n>", "Memory one agent needs, GB (default 1.5)").option("--reserve-gb <n>", "Memory never handed to agents, GB (default 2)").option("--per-agent-cores <n>", "Cores one agent keeps busy (default 2)").option("--reserve-cores <n>", "Cores never handed to agents (default 0)").option("--swap-threshold <ratio>", "Swap used/total above which the swap cap applies (default 0.75)").option("--swap-cap <n>", "Slots allowed while swap is above the threshold (default 2)").option("--per-agent-disk-gb <n>", "Disk one agent needs, GB (default 1)").option("--reserve-disk-gb <n>", "Disk never handed to agents, GB (default 3)").option("--json", "Emit one-line JSON instead of text", false).action((opts) => {
|
|
127216
127796
|
process.exit(capacityCommand(opts));
|
|
127217
127797
|
});
|
|
127798
|
+
program.command("gate").description("Fast pre-commit regression gate: did this change break a page that was fine at the last accepted state? Loads each page x viewport once (one browser, sequential, primed) and compares status, server HTML size, NEW section-crash / hydration / uncaught errors, page height after the scroll, interactive element count, server-rendered first-viewport sections and click-blocking overlays against `<dir>/gate-baseline.json`, a baseline of the candidate itself (NOT prod: that is `parity run`). No flows, no pixel diff, no vitals: it judges a page as it loads, so an interaction that breaks (a drawer that opens and ignores clicks) is not caught. Exits 0 no regression with at least one page compared, 1 a regression, 2 could not judge (cold or degraded candidate, no pages, no baseline, nothing compared) -- never 0 on an empty comparison. --update-baseline accepts the current state, and refuses when any page is unjudgeable.").requiredOption("--cand <url>", "Candidate base URL").option("--pages <list>", "Comma-separated paths (default: --golden's pages, else the baseline's)").option("--pages-file <path>", "File of paths, one per line").option("--golden <dir>", "A --record recording: its pages, and prod's page height so a change toward prod is an improvement").option("--viewports <list>", "mobile,tablet,desktop", "mobile,desktop").option("--dir <path>", "Directory holding gate-baseline.json (the target's .parity)", ".parity").option("--only <list>", "Restrict to these paths (the pages a change touched)").option("--update-baseline", "Accept the current state as the baseline (merges; refuses if any page is unjudgeable)", false).option("--json", "Emit one-line JSON instead of text", false).action(async (opts) => {
|
|
127799
|
+
process.exit(await gateCommand(opts));
|
|
127800
|
+
});
|
|
127218
127801
|
program.command("variance").description("Measure whether a score change is attributable to the code. Run `parity run` twice against UNCHANGED code, then pass both run ids: this reports the score spread and, more usefully, WHICH checks reported differently. A check whose status flips between two runs of the same code is not measuring the code, and every score it contributes to is unfalsifiable until it is named. Exits 1 when unstable, 2 when the runs are not comparable.").argument("<runIds...>", "Two or more saved run ids of the same host pair").option("--score-budget <points>", "Score spread tolerated before calling it unstable", "1").option("--output <dir>", "Output directory holding the runs", "./parity-output").option("--json", "Emit one-line JSON instead of pretty text", false).action((runIds, opts) => {
|
|
127219
127802
|
process.exit(varianceCommand({
|
|
127220
127803
|
runIds,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.36",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with a ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|