@decocms/parity 0.35.32 → 0.35.34

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 CHANGED
@@ -163,7 +163,7 @@ Hard caps already in place:
163
163
  - **A page that was never captured (status 0) is not a status divergence.** `http-status-parity` files one inconclusive `http-status:not-captured:<page>` finding, the run gets a `cand-pages-not-captured` (or `prod-…`) caveat listing the paths, and the check is `warn`. A real 404/500 stays critical. Re-run against a warm server before reading the score.
164
164
  - **`[hydration]` console errors are React's own hydration messages only.** A section that threw and was caught by an error boundary is `[section-crash]` (same severity); its `file:line` positions come from the candidate's build at capture time and may be stale against the working tree.
165
165
  - **`Issue.page` is the `path::viewport` key**, never a URL; the URL is in `details`.
166
- - **A local dev candidate (`--cand http://localhost:…`) is cold on its first request to each route.** A run started right after the server came up, or after adding routes, can time out on pages the server would answer in milliseconds once requested. `parity run` primes the candidate's pages one at a time and retries a never-answered capture once; if it still prints "warm-up/priming loads never answered" or a `cand-cold` caveat, the server was not ready: request the routes yourself (or wait) and re-run, and do not read the "status divergente: cand=0" findings as defects. Flows' own PLP/PDP navigations are not primed. `--no-prime-cand` turns priming off.
166
+ - **A local dev candidate (`--cand http://localhost:…`) is cold on its first request to each route.** A run started right after the server came up, or after adding routes, can time out on pages the server would answer in milliseconds once requested. `parity run` primes the candidate's pages one at a time and retries a never-answered capture once; if it still prints "warm-up/priming loads never answered" or a `cand-cold` caveat, the server was not ready: request the routes yourself (or wait) and re-run, and do not read the "status divergente: cand=0" findings as defects. A server can also go bad DURING the run (a dev server's loader de-duplication wedges after aborted requests): `parity run` re-requests the primed URLs after the passes and, when they or several captures show a collapsed document / no answer / a new 5xx, adds a `cand-degraded` caveat and marks the captures with their own evidence `candDegraded`; `runAllChecks` withholds those pairs from every check (`withHealthyCand`) as inconclusive. Do not read pages missing sections or a "section crashed" console error from such a run as defects: restart the server and re-run. A check's own fetch probes against a local URL must not use a short timeout (use `probeTimeoutMs`): the abort is what wedges it. Flows' own PLP/PDP navigations are not primed (so cannot be judged degraded). `--no-prime-cand` turns priming off.
167
167
  - **`parity run` doesn't apply schema changes from old runs** — if you change `src/types/schema.ts`, old `report.json` files won't parse. Delete `parity-output/` or re-run.
168
168
 
169
169
  ## Files agents should and should not write
package/CHANGELOG.md CHANGED
@@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
9
9
 
10
10
  ### Added
11
11
 
12
+ * **`parity run` notices a local candidate that degrades mid-run.** Priming records each URL's
13
+ status, document bytes and time; after the passes the same URLs are re-requested once, in order,
14
+ and compared (tolerances in `TOLERANCES.candHealth`). When the server is found degraded, a
15
+ `cand-degraded` run caveat names the URLs with before/after numbers, one summary line is printed,
16
+ `report.json.candHealth` records it, and every candidate capture that carries its own evidence
17
+ (`PageCapture.candDegraded`, also in recordings) is withheld from all checks as `inconclusive`
18
+ (`withHealthyCand`, applied in `runAllChecks`, so `parity replay` agrees). Captures without such
19
+ evidence are judged live, and a consistent 404/500 is never treated as degradation. A local
20
+ candidate also gets 2 simultaneous capture contexts in the extra-vitals and visual passes (prod
21
+ keeps 4), and the link/SSR probes of `nav-links-health`, `footer-links-health`, `ssr-no-js`,
22
+ `favicon-parity`, `plp-sorting` and `plp-pagination` wait 60s on a local URL instead of aborting
23
+ after 8-15s, since an aborted request is what wedges a dev server's loader de-duplication.
24
+
12
25
  * **`first-viewport-ssr` check (html module)** answers "is what the user sees in the first viewport
13
26
  already in the server response, or does it arrive later?". A deferred header (a skeleton in the
14
27
  server HTML that client JS fills in) passed `ssr-no-js` (the rest of the page carried the text)
@@ -81,6 +94,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
81
94
 
82
95
  ### Fixed
83
96
 
97
+ * **A dev-server candidate no longer fails the run on numbers the dev server itself produces.**
98
+ `cache-coverage` ("22 cacheable requests are not cached", hit rate down 54 points),
99
+ `network-summary-delta` (request volume 7x prod) and `web-vitals-mobile` were filed live against
100
+ a Vite dev server, while the `cand-dev-server` caveat said those numbers were not representative.
101
+ When cand is on a loopback host AND its captures show the dev toolchain (`/@vite/client`,
102
+ `/@react-refresh`, `/@id/`, `/node_modules/.vite/`, Next/webpack HMR, raw `/src/*.tsx` requests,
103
+ or the dev client tag in the HTML), the cand-derived findings of those checks, of
104
+ `lighthouse-opportunities`, of `lighthouse-scores` (performance category only) and of
105
+ `cookie-cep-modal-cls` are `inconclusive`: kept with a note, out of the score, check `warn`
106
+ rather than `fail`, pairs counted as inconclusive. A request that 404s, a lost deco section, an
107
+ accessibility score drop etc. stay live. A production build served on localhost is NOT a dev
108
+ server and keeps every finding (it now gets an info `cand-local-build` caveat instead of
109
+ `cand-dev-server`). The verdict is derived from the recorded captures, so `replay` / `--golden`
110
+ agree; no new recorded field.
111
+
84
112
  * **The compared / passed counts agree across checks again.** Three changes that each assumed
85
113
  the others were already in: a pair a not-captured guard (`withCapturedPairs`) withholds now
86
114
  lands in the check's `inconclusive` count (a check that does not count stays uncounted);
package/dist/cli.js CHANGED
@@ -76806,6 +76806,38 @@ var TOLERANCES = {
76806
76806
  note: "A page-height difference at or above this is `high`: a block of content is missing or extra."
76807
76807
  }
76808
76808
  },
76809
+ candHealth: {
76810
+ bytesCollapseRatio: {
76811
+ value: 0.25,
76812
+ unit: "ratio (0-1) of the primed document bytes",
76813
+ basis: "assumed",
76814
+ note: "A local candidate's document smaller than this share of what the same URL weighed at priming is a degraded answer (a wedged dev server returned 245 KB for a ~1.9 MB page, 13%). Deliberately far below 1: mobile and desktop SSR, A/B copy and a different cart state move a document by tens of percent, not by 4x."
76815
+ },
76816
+ slowRatio: {
76817
+ value: 5,
76818
+ unit: "x primed response time",
76819
+ basis: "assumed",
76820
+ note: "A re-request this many times slower than the priming load counts as slow, subject to slowFloorMs. The priming load is the cold compile, so a warm server is expected to be FASTER than it; slower by this much is not jitter."
76821
+ },
76822
+ slowFloorMs: {
76823
+ value: 5000,
76824
+ unit: "ms",
76825
+ basis: "assumed",
76826
+ note: "A response under this is never slow, whatever the ratio: 20 ms to 150 ms is 7x and means nothing."
76827
+ },
76828
+ slowMinUrls: {
76829
+ value: 2,
76830
+ unit: "count",
76831
+ basis: "assumed",
76832
+ note: "Slowness alone needs this many URLs to agree before the candidate is called degraded; one slow request is a GC pause, a compile or a busy machine. Hard evidence (no answer, a 5xx the prime did not see, collapsed bytes) is enough on one URL."
76833
+ },
76834
+ collapsedCapturesMin: {
76835
+ value: 2,
76836
+ unit: "count",
76837
+ basis: "assumed",
76838
+ note: "Without a failing re-request, this many captures with a collapsed document is what it takes to call the run degraded from the captures alone (the server may have recovered by the end of the run)."
76839
+ }
76840
+ },
76809
76841
  clickProbe: {
76810
76842
  gridCols: {
76811
76843
  value: 5,
@@ -78011,6 +78043,44 @@ function buildCacheReport(entries, baseUrl) {
78011
78043
  };
78012
78044
  }
78013
78045
 
78046
+ // src/checks/lib/dev-server.ts
78047
+ var DEV_URL_MARKERS = [
78048
+ /\/@vite\/client/,
78049
+ /\/@react-refresh/,
78050
+ /\/@id\//,
78051
+ /\/@fs\//,
78052
+ /\/node_modules\/\.vite\//,
78053
+ /\/__vite_ping/,
78054
+ /\/_next\/webpack-hmr/,
78055
+ /\/_next\/static\/development\//,
78056
+ /\/webpack-dev-server\//,
78057
+ /\/sockjs-node\//,
78058
+ /\.hot-update\.(json|js)(\?|$)/,
78059
+ /\/src\/[^?#]*\.(tsx|ts|jsx)(\?|#|$)/
78060
+ ];
78061
+ var DEV_HTML_MARKERS = [/\/@vite\/client/, /\/@react-refresh/, /\/_next\/webpack-hmr/];
78062
+ function isCandDevServer(candPages, candIsProduction = false) {
78063
+ if (candIsProduction)
78064
+ return false;
78065
+ const host = siteHost(candPages);
78066
+ if (!host || !isLoopbackHost(host))
78067
+ return false;
78068
+ return candPages.some((p) => {
78069
+ const html = p.html ?? "";
78070
+ return (p.network ?? []).some((e) => DEV_URL_MARKERS.some((re) => re.test(e.url))) || DEV_HTML_MARKERS.some((re) => re.test(html));
78071
+ });
78072
+ }
78073
+ var DEV_SERVER_NOTE = "Medido contra um dev server (cand-dev-server): sem minificação, sem cache de edge, módulos sem bundle. Este número não é evidência sobre a migração — reconfirme contra um build de produção.";
78074
+ function asDevServerInconclusive(issue) {
78075
+ return {
78076
+ ...issue,
78077
+ inconclusive: true,
78078
+ details: issue.details ? `${DEV_SERVER_NOTE}
78079
+
78080
+ ${issue.details}` : DEV_SERVER_NOTE
78081
+ };
78082
+ }
78083
+
78014
78084
  // src/checks/cache-coverage.ts
78015
78085
  function cacheCoverage(ctx) {
78016
78086
  const start = Date.now();
@@ -78075,14 +78145,27 @@ Cache-Control: ${opp.entry.cacheControl ?? "(missing)"}
78075
78145
  Status: ${opp.entry.status}`
78076
78146
  });
78077
78147
  }
78078
- const status = issues.some((i) => i.severity === "high") ? "fail" : issues.length > 0 ? "warn" : "pass";
78148
+ const devServer = isCandDevServer(ctx.candPages, ctx.candIsProduction);
78149
+ const reported = devServer ? issues.length > 0 ? issues.map(asDevServerInconclusive) : [
78150
+ {
78151
+ id: "cache:dev-server-not-judged",
78152
+ severity: "low",
78153
+ inconclusive: true,
78154
+ category: "performance",
78155
+ check: "cache-coverage",
78156
+ summary: "Cache de cand não julgado: dev server (cand-dev-server)",
78157
+ details: DEV_SERVER_NOTE
78158
+ }
78159
+ ] : issues;
78160
+ const live = reported.filter((i) => !i.inconclusive);
78161
+ const status = live.some((i) => i.severity === "high") ? "fail" : reported.length > 0 ? "warn" : "pass";
78079
78162
  return {
78080
78163
  name: "cache-coverage",
78081
78164
  status,
78082
78165
  severity: "high",
78083
78166
  durationMs: Date.now() - start,
78084
- summary: `Cache hit rate cand: ${(report.hitRate * 100).toFixed(0)}% · ${oppCount} oportunidade(s) (${(oppBytes / 1024).toFixed(0)} KB)`,
78085
- issues,
78167
+ summary: `Cache hit rate cand: ${(report.hitRate * 100).toFixed(0)}% · ${oppCount} oportunidade(s) (${(oppBytes / 1024).toFixed(0)} KB)${devServer ? " · dev server: inconclusivo" : ""}`,
78168
+ issues: reported,
78086
78169
  data: {
78087
78170
  hitRate: report.hitRate,
78088
78171
  prodHitRate: prodReport?.hitRate,
@@ -78943,14 +79026,15 @@ function cookieCepModalCls(ctx) {
78943
79026
  }
78944
79027
  }
78945
79028
  }
78946
- const status = issues.some((i) => i.severity === "critical" || i.severity === "high") ? "fail" : issues.length > 0 ? "warn" : "pass";
79029
+ const reported = isCandDevServer(ctx.candPages, ctx.candIsProduction) ? issues.map(asDevServerInconclusive) : issues;
79030
+ const status = reported.some((i) => !i.inconclusive && (i.severity === "critical" || i.severity === "high")) ? "fail" : reported.length > 0 ? "warn" : "pass";
78947
79031
  return {
78948
79032
  name: "cookie-cep-modal-cls",
78949
79033
  status,
78950
79034
  severity: "high",
78951
79035
  durationMs: Date.now() - start,
78952
- summary: `${issues.length} issue(s)`,
78953
- issues
79036
+ summary: `${reported.length} issue(s)`,
79037
+ issues: reported
78954
79038
  };
78955
79039
  }
78956
79040
  function keyFor(p) {
@@ -78968,6 +79052,14 @@ function hasDialogLikeMarkup(page) {
78968
79052
 
78969
79053
  // src/checks/favicon-parity.ts
78970
79054
  init_esm10();
79055
+
79056
+ // src/checks/lib/probe-timeout.ts
79057
+ var LOCAL_PROBE_TIMEOUT_MS = 60000;
79058
+ function probeTimeoutMs(url, remoteMs) {
79059
+ return isLocalhost(url) ? Math.max(remoteMs, LOCAL_PROBE_TIMEOUT_MS) : remoteMs;
79060
+ }
79061
+
79062
+ // src/checks/favicon-parity.ts
78971
79063
  async function faviconParity(ctx) {
78972
79064
  const start = Date.now();
78973
79065
  const issues = [];
@@ -79046,7 +79138,7 @@ async function hashUrl(href, base) {
79046
79138
  return null;
79047
79139
  }
79048
79140
  try {
79049
- const res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(8000) });
79141
+ const res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(probeTimeoutMs(url, 8000)) });
79050
79142
  if (!res.ok)
79051
79143
  return null;
79052
79144
  const buf = await res.arrayBuffer();
@@ -79346,7 +79438,7 @@ async function probeLinks(urls) {
79346
79438
  const res = await fetch(url, {
79347
79439
  method: "HEAD",
79348
79440
  redirect: "follow",
79349
- signal: AbortSignal.timeout(8000)
79441
+ signal: AbortSignal.timeout(probeTimeoutMs(url, 8000))
79350
79442
  });
79351
79443
  return { url, status: res.status, durationMs: Date.now() - t };
79352
79444
  } catch {
@@ -79897,6 +79989,39 @@ function extractSectionIds(entries) {
79897
79989
  return out;
79898
79990
  }
79899
79991
 
79992
+ // src/checks/lib/cand-degraded.ts
79993
+ function withHealthyCand(check) {
79994
+ const guarded = async (ctx) => {
79995
+ const bad = new Map;
79996
+ for (const p of ctx.candPages)
79997
+ if (p.candDegraded)
79998
+ bad.set(captureKey(p), p);
79999
+ if (bad.size === 0)
80000
+ return check(ctx);
80001
+ const keep = (pages) => pages.filter((p) => !bad.has(captureKey(p)));
80002
+ const result = await check({ ...ctx, prodPages: keep(ctx.prodPages), candPages: keep(ctx.candPages) });
80003
+ const issues = [...bad].map(([key, page]) => ({
80004
+ id: `${result.name}:cand-degraded:${key}`,
80005
+ severity: "low",
80006
+ inconclusive: true,
80007
+ category: "functional",
80008
+ page: key,
80009
+ check: result.name,
80010
+ summary: `${key}: captured while the candidate was degraded; re-run against a warm/healthy server — not compared by ${result.name}`,
80011
+ details: `The local candidate server degraded during this run (${page.candDegraded}). A page captured in that state is truncated, so judging it reports the server's condition as the site's. Not a finding about the page.`
80012
+ }));
80013
+ const pairKeys = new Set(pairCaptures(ctx.prodPages, ctx.candPages).pairs.map((p) => p.key));
80014
+ const withheld = [...bad.keys()].filter((k) => pairKeys.has(k)).length;
80015
+ return addWithheld({
80016
+ ...result,
80017
+ status: result.status === "pass" ? "warn" : result.status,
80018
+ issues: [...result.issues, ...issues]
80019
+ }, withheld);
80020
+ };
80021
+ Object.defineProperty(guarded, "name", { value: check.name });
80022
+ return guarded;
80023
+ }
80024
+
79900
80025
  // src/checks/lib/html-snapshot.ts
79901
80026
  function htmlUnread(page) {
79902
80027
  return page.htmlSnapshotFailed === true || !page.html;
@@ -80357,7 +80482,7 @@ async function probeRoutes(links, base) {
80357
80482
  const res = await fetch(url, {
80358
80483
  method: "HEAD",
80359
80484
  redirect: "follow",
80360
- signal: AbortSignal.timeout(8000)
80485
+ signal: AbortSignal.timeout(probeTimeoutMs(url, 8000))
80361
80486
  });
80362
80487
  return { path, status: res.status };
80363
80488
  } catch {
@@ -80576,13 +80701,14 @@ function networkSummaryDelta(ctx) {
80576
80701
  const start = Date.now();
80577
80702
  const { pairs } = pairCaptures(ctx.prodPages, ctx.candPages);
80578
80703
  const issues = [];
80704
+ const devServer = isCandDevServer(ctx.candPages, ctx.candIsProduction);
80579
80705
  for (const pair of pairs) {
80580
80706
  const diff = diffNetwork(pair.prod.network, pair.cand.network, {
80581
80707
  ignorePatterns: ctx.ignore.ignoreRequestPatterns,
80582
80708
  maxTotalPct: TOLERANCES.network.maxTotalPct.value
80583
80709
  });
80584
80710
  if (diff.anyFailed) {
80585
- issues.push({
80711
+ const volume = {
80586
80712
  id: `network:volume:${pair.key}`,
80587
80713
  severity: "medium",
80588
80714
  category: "network",
@@ -80596,7 +80722,8 @@ function networkSummaryDelta(ctx) {
80596
80722
  `URLs apenas em cand (${diff.urls.onlyCand.length} primeiras 5): ${diff.urls.onlyCand.slice(0, 5).join(", ")}`
80597
80723
  ].join(`
80598
80724
  `)
80599
- });
80725
+ };
80726
+ issues.push(devServer ? asDevServerInconclusive(volume) : volume);
80600
80727
  }
80601
80728
  const prodApi = new Set(diff.prod.decoSectionsHit);
80602
80729
  for (const sec of prodApi) {
@@ -81672,7 +81799,7 @@ async function fetchPlpProducts(url) {
81672
81799
  headers: {
81673
81800
  "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
81674
81801
  },
81675
- signal: AbortSignal.timeout(15000)
81802
+ signal: AbortSignal.timeout(probeTimeoutMs(url, 15000))
81676
81803
  });
81677
81804
  if (res.status !== 200) {
81678
81805
  return { status: res.status, productPaths: [] };
@@ -81752,7 +81879,7 @@ async function discoverPlpFromHome(homeUrl) {
81752
81879
  headers: {
81753
81880
  "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
81754
81881
  },
81755
- signal: AbortSignal.timeout(15000)
81882
+ signal: AbortSignal.timeout(probeTimeoutMs(homeUrl, 15000))
81756
81883
  });
81757
81884
  if (!res.ok)
81758
81885
  return null;
@@ -81925,7 +82052,7 @@ async function fetchOrderedHrefs(url) {
81925
82052
  headers: {
81926
82053
  "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
81927
82054
  },
81928
- signal: AbortSignal.timeout(15000)
82055
+ signal: AbortSignal.timeout(probeTimeoutMs(url, 15000))
81929
82056
  });
81930
82057
  if (res.status !== 200)
81931
82058
  return { status: res.status, hrefs: [] };
@@ -83512,7 +83639,7 @@ async function ssrNoJs(ctx) {
83512
83639
  }
83513
83640
  async function fetchSsrText(url) {
83514
83641
  try {
83515
- const res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(15000) });
83642
+ const res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(probeTimeoutMs(url, 15000)) });
83516
83643
  if (!res.ok)
83517
83644
  return null;
83518
83645
  const html = await res.text();
@@ -90906,6 +91033,7 @@ function webVitalsMobile(ctx) {
90906
91033
  const { pairs } = pairCaptures(ctx.prodPages, ctx.candPages);
90907
91034
  const mobilePairs = pairs.filter((p) => p.viewport === "mobile");
90908
91035
  const issues = [];
91036
+ const devServer = isCandDevServer(ctx.candPages, ctx.candIsProduction);
90909
91037
  for (const pair of mobilePairs) {
90910
91038
  const diff = diffVitals(pair.prod.vitals, pair.cand.vitals, DEFAULT_THRESHOLDS);
90911
91039
  if (!diff.anyFailed)
@@ -90916,7 +91044,7 @@ function webVitalsMobile(ctx) {
90916
91044
  return `${k.toUpperCase()}: prod=${fmt(v.prod)}, cand=${fmt(v.cand)} (${v.reason})`;
90917
91045
  }).join(`
90918
91046
  `);
90919
- issues.push({
91047
+ const regression = {
90920
91048
  id: `vitals:${pair.key}`,
90921
91049
  severity: "high",
90922
91050
  category: "performance",
@@ -90928,11 +91056,13 @@ function webVitalsMobile(ctx) {
90928
91056
  { kind: "screenshot", path: pair.prod.screenshotPath, label: "prod" },
90929
91057
  { kind: "screenshot", path: pair.cand.screenshotPath, label: "cand" }
90930
91058
  ]
90931
- });
91059
+ };
91060
+ issues.push(devServer ? asDevServerInconclusive(regression) : regression);
90932
91061
  }
91062
+ const live = issues.filter((i) => !i.inconclusive);
90933
91063
  return {
90934
91064
  name: "web-vitals-mobile",
90935
- status: issues.length > 0 ? "fail" : "pass",
91065
+ status: live.length > 0 ? "fail" : issues.length > 0 ? "warn" : "pass",
90936
91066
  severity: "high",
90937
91067
  durationMs: Date.now() - start,
90938
91068
  summary: `${mobilePairs.length} página(s) mobile, ${issues.length} regressão(ões)`,
@@ -91091,7 +91221,7 @@ async function runAllChecks(ctx, outResults, checkFilter) {
91091
91221
  await Promise.all(checksToRun.map(async (check, i) => {
91092
91222
  const start = Date.now();
91093
91223
  try {
91094
- const r = await check(ctx);
91224
+ const r = await withHealthyCand(check)(ctx);
91095
91225
  push({ ...r, durationMs: r.durationMs || Date.now() - start }, i);
91096
91226
  } catch (err) {
91097
91227
  push({
@@ -91434,6 +91564,7 @@ var PageCapture = z2.object({
91434
91564
  pass: z2.enum(["extra", "visual"]).optional(),
91435
91565
  variant: VariantFingerprint.optional(),
91436
91566
  retried: z2.boolean().optional(),
91567
+ candDegraded: z2.string().optional(),
91437
91568
  clickProbe: ClickProbe.optional(),
91438
91569
  firstViewport: FirstViewportProbe.optional()
91439
91570
  });
@@ -91788,6 +91919,17 @@ var Run = z2.object({
91788
91919
  partial: z2.boolean().optional(),
91789
91920
  partialReason: z2.string().optional(),
91790
91921
  caveats: z2.array(RunCaveat).optional(),
91922
+ candHealth: z2.object({
91923
+ degraded: z2.boolean(),
91924
+ baselined: z2.number(),
91925
+ captures: z2.number(),
91926
+ evidence: z2.array(z2.object({
91927
+ url: z2.string(),
91928
+ kind: z2.enum(["no-answer", "server-error", "bytes-collapsed", "slow"]),
91929
+ before: z2.object({ status: z2.number(), bytes: z2.number().nullable(), ms: z2.number() }),
91930
+ after: z2.object({ status: z2.number(), bytes: z2.number().nullable(), ms: z2.number() })
91931
+ }))
91932
+ }).optional(),
91791
91933
  pinned: z2.object({
91792
91934
  prod: z2.object({ cookies: z2.array(z2.string()), headers: z2.array(z2.string()) }),
91793
91935
  cand: z2.object({ cookies: z2.array(z2.string()), headers: z2.array(z2.string()) })
@@ -119423,7 +119565,7 @@ async function primeSequentially(urls, primed, prime) {
119423
119565
  }
119424
119566
  return { attempted: urls.length, failed, totalMs: Date.now() - start };
119425
119567
  }
119426
- async function primeCandUrls(browser, urls, primed, ctxOpts) {
119568
+ async function primeCandUrls(browser, urls, primed, ctxOpts, baselines) {
119427
119569
  if (urls.length === 0)
119428
119570
  return { attempted: 0, failed: [], totalMs: 0 };
119429
119571
  const ctx = await newContext(browser, { cohortCookieValue: "control", ...ctxOpts });
@@ -119431,7 +119573,12 @@ async function primeCandUrls(browser, urls, primed, ctxOpts) {
119431
119573
  return await primeSequentially(urls, primed, async (url) => {
119432
119574
  const page = await ctx.newPage();
119433
119575
  try {
119434
- await page.goto(url, { waitUntil: "domcontentloaded", timeout: PRIME_TIMEOUT_MS });
119576
+ const t = Date.now();
119577
+ const res = await page.goto(url, { waitUntil: "domcontentloaded", timeout: PRIME_TIMEOUT_MS });
119578
+ if (baselines && res) {
119579
+ const bytes = await res.body().then((b) => b.byteLength, () => null);
119580
+ baselines.set(url, { url, status: res.status(), bytes, ms: Date.now() - t });
119581
+ }
119435
119582
  await page.waitForLoadState("load", { timeout: PRIME_LOAD_MS }).catch(() => {
119436
119583
  return;
119437
119584
  });
@@ -119463,7 +119610,16 @@ function isColdCandidate(loads) {
119463
119610
  // src/engine/run-context.ts
119464
119611
  function detectRunCaveats(input) {
119465
119612
  const out = [];
119466
- if (isLocalhost(input.candUrl)) {
119613
+ const candHost = siteHost(input.candPages);
119614
+ const localBuild = isLocalhost(input.candUrl) && !input.candIsProduction && candHost !== null && isLoopbackHost(candHost) && input.candPages.some((p) => (p.network?.length ?? 0) > 0) && !isCandDevServer(input.candPages, input.candIsProduction);
119615
+ if (localBuild) {
119616
+ out.push({
119617
+ id: "cand-local-build",
119618
+ level: "info",
119619
+ summary: "Candidato servido localmente, sem sinais de dev server",
119620
+ detail: "Nenhum marcador de dev server (HMR, módulos sem bundle) nas capturas: cache, volume de requests e vitals foram julgados como num host remoto. Se este local é na verdade um dev server, os números de performance não são representativos."
119621
+ });
119622
+ } else if (isLocalhost(input.candUrl)) {
119467
119623
  out.push({
119468
119624
  id: "cand-dev-server",
119469
119625
  level: "warn",
@@ -119480,6 +119636,17 @@ function detectRunCaveats(input) {
119480
119636
  detail: "Pages that did not answer are missing from this run or were measured cold, so counts, vitals and status findings of the affected routes are not a fair comparison. Wait for the candidate to finish starting, or request each route once, then re-run."
119481
119637
  });
119482
119638
  }
119639
+ if (input.candHealth?.degraded) {
119640
+ const h = input.candHealth;
119641
+ const kb = (n) => n === null ? "?" : `${Math.round(n / 1024)} KB`;
119642
+ const what = (e) => `${e.url} (${kb(e.before.bytes)} / ${e.before.status} / ${Math.round(e.before.ms)} ms at priming, ${kb(e.after.bytes)} / ${e.after.status} / ${Math.round(e.after.ms)} ms after the passes)`;
119643
+ out.push({
119644
+ id: "cand-degraded",
119645
+ level: "warn",
119646
+ summary: `The candidate server degraded during the run — ${h.captures} capture(s) were withheld as inconclusive`,
119647
+ detail: `A local dev server can wedge mid-run (aborted requests leave loaders that never settle), after which pages come back truncated. ${h.captures} candidate capture(s) carrying their own evidence of it (document collapsed against the priming baseline, no answer after a good prime, a 5xx priming did not see) were not judged by any check; the score does not include them, so it is optimistic by exactly those pages. Captures without that evidence were judged normally. Restart the server and re-run (or use a production build). Re-request after the passes: ${h.evidence.length > 0 ? h.evidence.map(what).join("; ") : "answered like at priming (the degradation was seen in the captures)"}.`
119648
+ });
119649
+ }
119483
119650
  if (isLocalhost(input.prodUrl)) {
119484
119651
  out.push({
119485
119652
  id: "prod-dev-server",
@@ -119631,6 +119798,113 @@ function describePin(pin) {
119631
119798
  ].join(", ");
119632
119799
  }
119633
119800
 
119801
+ // src/engine/cand-health.ts
119802
+ var T2 = TOLERANCES.candHealth;
119803
+ function judgeProbe(before, after) {
119804
+ if (before.status === 0)
119805
+ return null;
119806
+ if (after.status === 0)
119807
+ return "no-answer";
119808
+ if (after.status >= 500 && before.status < 500)
119809
+ return "server-error";
119810
+ if (after.status !== before.status && after.status >= 400 && before.status < 400) {
119811
+ return "server-error";
119812
+ }
119813
+ if (before.bytes !== null && after.bytes !== null && before.bytes > 0 && after.bytes < before.bytes * T2.bytesCollapseRatio.value) {
119814
+ return "bytes-collapsed";
119815
+ }
119816
+ if (after.ms >= Math.max(before.ms * T2.slowRatio.value, T2.slowFloorMs.value))
119817
+ return "slow";
119818
+ return null;
119819
+ }
119820
+ function judgeRecheck(baselines, after) {
119821
+ const evidence = [];
119822
+ for (const [url, before] of baselines) {
119823
+ const now = after.get(url);
119824
+ if (!now)
119825
+ continue;
119826
+ const kind = judgeProbe(before, now);
119827
+ if (kind)
119828
+ evidence.push({ url, kind, before, after: now });
119829
+ }
119830
+ const hard = evidence.some((e) => e.kind !== "slow");
119831
+ const slow = evidence.filter((e) => e.kind === "slow").length;
119832
+ return { degraded: hard || slow >= T2.slowMinUrls.value, evidence };
119833
+ }
119834
+ function documentEntry(cap) {
119835
+ const docs = cap.network.filter((n) => n.resourceType === "document" && n.method === "GET");
119836
+ return docs.find((n) => n.url === cap.url || n.url === cap.finalUrl) ?? docs[0];
119837
+ }
119838
+ function captureDegradation(cap, baselines) {
119839
+ if (cap.side !== "cand")
119840
+ return null;
119841
+ const before = baselines.get(cap.url);
119842
+ if (!before || before.status === 0)
119843
+ return null;
119844
+ if (cap.status === 0) {
119845
+ return { kind: "no-answer", text: `no answer (the priming load answered ${before.status})` };
119846
+ }
119847
+ const doc = documentEntry(cap);
119848
+ const kind = judgeProbe(before, {
119849
+ status: cap.status,
119850
+ bytes: doc?.bytes ?? null,
119851
+ ms: doc?.durationMs ?? 0
119852
+ });
119853
+ if (!kind)
119854
+ return null;
119855
+ const kb = (n) => n === null ? "?" : `${Math.round(n / 1024)} KB`;
119856
+ const text = kind === "bytes-collapsed" ? `document ${kb(doc?.bytes ?? null)} against ${kb(before.bytes)} at priming` : kind === "slow" ? `document took ${Math.round((doc?.durationMs ?? 0) / 1000)}s against ${Math.round(before.ms / 1000)}s at priming` : `answered ${cap.status} where priming got ${before.status}`;
119857
+ return { kind, text };
119858
+ }
119859
+ function markDegradedCaptures(candPages, baselines, recheck) {
119860
+ if (baselines.size === 0)
119861
+ return { degraded: false, marked: 0 };
119862
+ const own = candPages.map((cap) => ({ cap, d: captureDegradation(cap, baselines) }));
119863
+ const collapsed = own.filter((o) => o.d?.kind === "bytes-collapsed").length;
119864
+ const degraded = recheck.degraded || collapsed >= T2.collapsedCapturesMin.value;
119865
+ if (!degraded)
119866
+ return { degraded: false, marked: 0 };
119867
+ let marked = 0;
119868
+ for (const { cap, d } of own) {
119869
+ if (!d)
119870
+ continue;
119871
+ cap.candDegraded = d.text;
119872
+ marked++;
119873
+ }
119874
+ return { degraded: true, marked };
119875
+ }
119876
+ async function recheckCand(urls, opts = {}) {
119877
+ const out = new Map;
119878
+ for (const url of urls) {
119879
+ const t = Date.now();
119880
+ try {
119881
+ const res = await fetch(url, {
119882
+ redirect: "follow",
119883
+ headers: opts.headers,
119884
+ signal: AbortSignal.timeout(opts.timeoutMs ?? 90000)
119885
+ });
119886
+ const body = await res.arrayBuffer();
119887
+ out.set(url, { status: res.status, bytes: body.byteLength, ms: Date.now() - t });
119888
+ } catch {
119889
+ out.set(url, { status: 0, bytes: null, ms: Date.now() - t });
119890
+ }
119891
+ }
119892
+ return out;
119893
+ }
119894
+ function buildCandHealthReport(baselines, recheck, marking) {
119895
+ return {
119896
+ degraded: marking.degraded,
119897
+ baselined: baselines.size,
119898
+ captures: marking.marked,
119899
+ evidence: recheck.evidence.map((e) => ({
119900
+ url: e.url,
119901
+ kind: e.kind,
119902
+ before: { status: e.before.status, bytes: e.before.bytes, ms: e.before.ms },
119903
+ after: e.after
119904
+ }))
119905
+ };
119906
+ }
119907
+
119634
119908
  // src/util/timing.ts
119635
119909
  async function withTiming(fn) {
119636
119910
  const start = performance.now();
@@ -120205,6 +120479,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120205
120479
  }
120206
120480
  const primeEnabled = opts.primeCand !== false && isLocalhost(opts.cand);
120207
120481
  const primed = new Set;
120482
+ const candBaselines = new Map;
120208
120483
  const primeAcc = { attempted: 0, failed: [], totalMs: 0 };
120209
120484
  const candRetry = { retried: 0, recovered: 0 };
120210
120485
  const retrying = new Set;
@@ -120231,7 +120506,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120231
120506
  viewport: viewports[0],
120232
120507
  cookies: pins.cand.cookies,
120233
120508
  headers: pins.cand.headers
120234
- });
120509
+ }, candBaselines);
120235
120510
  primeAcc.attempted += r.attempted;
120236
120511
  primeAcc.failed.push(...r.failed);
120237
120512
  primeAcc.totalMs += r.totalMs;
@@ -120534,7 +120809,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120534
120809
  extraSpinner.text = `[vitals extras] ${done}/${tasks.length} (último: ${task.path})`;
120535
120810
  }
120536
120811
  };
120537
- await runWithConcurrency2(tasks, 4, runTask);
120812
+ await runCapturePool(tasks, opts.cand, runTask);
120538
120813
  await retryColdCand("extra", tasks, runTask);
120539
120814
  vitalsHb.stop();
120540
120815
  extraSpinner.succeed(`+${extraPaths.length} página(s) com vitals`);
@@ -120631,7 +120906,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120631
120906
  visualSpinner.text = `[visual] ${done}/${tasks.length} (último: ${task.path})`;
120632
120907
  }
120633
120908
  };
120634
- await runWithConcurrency2(tasks, 4, runTask);
120909
+ await runCapturePool(tasks, opts.cand, runTask);
120635
120910
  await retryColdCand("visual", tasks, runTask);
120636
120911
  visualHb.stop();
120637
120912
  visualSpinner.succeed(`Visual diff: ${tasks.length} screenshot(s) capturado(s)`);
@@ -120683,6 +120958,15 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120683
120958
  viewports,
120684
120959
  candIsProduction: opts.candIsProduction
120685
120960
  };
120961
+ let candHealth;
120962
+ if (primeEnabled && candBaselines.size > 0) {
120963
+ const recheck = judgeRecheck(candBaselines, await recheckCand([...candBaselines.keys()], { headers: pinFetchHeaders(pins.cand) }));
120964
+ const marking = markDegradedCaptures(checkCtx.candPages, candBaselines, recheck);
120965
+ candHealth = buildCandHealthReport(candBaselines, recheck, marking);
120966
+ if (marking.degraded) {
120967
+ console.log(chalk34.yellow(` ! the candidate server degraded during the run — ${marking.marked} capture(s) withheld as inconclusive (restart it and re-run)`));
120968
+ }
120969
+ }
120686
120970
  let recordedOk = false;
120687
120971
  let goldenStale = [];
120688
120972
  if (opts.record) {
@@ -120835,8 +121119,10 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
120835
121119
  llmEnabled: llmStillAvailable,
120836
121120
  candIsProduction: opts.candIsProduction,
120837
121121
  prodPinned: !isEmptyPin(pins.prod),
120838
- warmLoads: warmLoadsNow()
121122
+ warmLoads: warmLoadsNow(),
121123
+ candHealth
120839
121124
  })),
121125
+ candHealth,
120840
121126
  pinned: isEmptyPin(pins.prod) && isEmptyPin(pins.cand) ? undefined : { prod: pinNames(pins.prod), cand: pinNames(pins.cand) },
120841
121127
  pagePairs,
120842
121128
  golden: goldenRec ? goldenReportField(resolve21(opts.golden), goldenRec.meta, goldenStale) : undefined
@@ -121058,6 +121344,15 @@ function formatPagePairTable(rows) {
121058
121344
  }).join(`
121059
121345
  `);
121060
121346
  }
121347
+ var LOCAL_CAND_CAPTURES = 2;
121348
+ async function runCapturePool(tasks, candBase, fn) {
121349
+ if (!isLocalhost(candBase))
121350
+ return runWithConcurrency2(tasks, 4, fn);
121351
+ await Promise.all([
121352
+ runWithConcurrency2(tasks.filter((t) => t.side !== "cand"), 4, fn),
121353
+ runWithConcurrency2(tasks.filter((t) => t.side === "cand"), LOCAL_CAND_CAPTURES, fn)
121354
+ ]);
121355
+ }
121061
121356
  async function runWithConcurrency2(items, workers, fn) {
121062
121357
  let next = 0;
121063
121358
  await Promise.all(Array.from({ length: workers }, async () => {
@@ -123352,11 +123647,11 @@ function L2(pt, en, lang) {
123352
123647
  const initial = lang === "pt" ? pt : en;
123353
123648
  return `<span class="i18n" data-pt="${esc3(pt)}" data-en="${esc3(en)}">${esc3(initial)}</span>`;
123354
123649
  }
123355
- function T2(text, lang) {
123650
+ function T3(text, lang) {
123356
123651
  return L2(text.pt, text.en, lang);
123357
123652
  }
123358
123653
  function tiles(items, lang) {
123359
- const cells = items.map((t) => `<div class="tile"><div class="tile-val ${TONE_CLASS[t.tone]}">${esc3(t.value)}</div><div class="tile-label">${T2(t.label, lang)}</div>${t.sub ? `<div class="tile-sub">${T2(t.sub, lang)}</div>` : ""}</div>`).join("");
123654
+ const cells = items.map((t) => `<div class="tile"><div class="tile-val ${TONE_CLASS[t.tone]}">${esc3(t.value)}</div><div class="tile-label">${T3(t.label, lang)}</div>${t.sub ? `<div class="tile-sub">${T3(t.sub, lang)}</div>` : ""}</div>`).join("");
123360
123655
  return `<div class="stat-grid">${cells}</div>`;
123361
123656
  }
123362
123657
  function page(eyebrow, title, body, note) {
@@ -125812,9 +126107,10 @@ function lighthouseOpportunities(ctx) {
125812
126107
  }
125813
126108
  const deltas = diffOpportunities(ctx.prodPages, ctx.candPages);
125814
126109
  const reportable = deltas.filter((d) => opportunitySeverity(d.cand.savingsMs) !== "low");
126110
+ const devServer = isCandDevServer(ctx.candPages, ctx.candIsProduction);
125815
126111
  const issues = reportable.map((d) => {
125816
126112
  const sev = opportunitySeverity(d.cand.savingsMs);
125817
- return {
126113
+ const issue = {
125818
126114
  id: `lh:${d.cand.id}`,
125819
126115
  severity: d.regression && sev === "medium" ? "high" : sev,
125820
126116
  category: "performance",
@@ -125822,6 +126118,7 @@ function lighthouseOpportunities(ctx) {
125822
126118
  summary: `${d.cand.title} — ${fmtMs2(d.cand.savingsMs)} recuperáveis${d.regression ? " (regressão: prod não tem, ou tem bem menos)" : ""}`,
125823
126119
  details: buildDetails(d.cand, d.prod, d.regression)
125824
126120
  };
126121
+ return devServer ? asDevServerInconclusive(issue) : issue;
125825
126122
  });
125826
126123
  const dropped = deltas.length - reportable.length;
125827
126124
  const worst = reportable[0]?.cand;
@@ -125833,7 +126130,7 @@ function lighthouseOpportunities(ctx) {
125833
126130
  ].filter(Boolean);
125834
126131
  return {
125835
126132
  name,
125836
- status: issues.length > 0 ? "fail" : "pass",
126133
+ status: issues.some((i) => !i.inconclusive) ? "fail" : issues.length > 0 ? "warn" : "pass",
125837
126134
  severity: "medium",
125838
126135
  durationMs: Date.now() - start,
125839
126136
  summary: summaryParts.join(", "),
@@ -125876,6 +126173,7 @@ function lighthouseScores(ctx) {
125876
126173
  const start = Date.now();
125877
126174
  const { pairs } = pairCaptures(ctx.prodPages, ctx.candPages);
125878
126175
  const issues = [];
126176
+ const devServer = isCandDevServer(ctx.candPages, ctx.candIsProduction);
125879
126177
  for (const pair of pairs) {
125880
126178
  const prod = pair.prod.lhScores;
125881
126179
  const cand = pair.cand.lhScores;
@@ -125889,7 +126187,7 @@ function lighthouseScores(ctx) {
125889
126187
  const delta = c - p;
125890
126188
  if (delta >= -REGRESSION_DELTA)
125891
126189
  continue;
125892
- issues.push({
126190
+ const regression = {
125893
126191
  id: `lh-score:${key}:${pair.key}`,
125894
126192
  severity: -delta >= TOLERANCES.vitals.lighthouseScoreHighDrop.value ? "high" : "medium",
125895
126193
  category: key === "seo" ? "seo" : key === "accessibility" ? "a11y" : "performance",
@@ -125897,13 +126195,14 @@ function lighthouseScores(ctx) {
125897
126195
  check: "lighthouse-scores",
125898
126196
  summary: `${label} regrediu em ${pair.key}: cand ${c} vs prod ${p} (${delta})`,
125899
126197
  details: `Objetivo da migração é igual ou melhor. ${label}: prod=${p}, cand=${c}. Recupere pelo menos o nível de prod.`
125900
- });
126198
+ };
126199
+ issues.push(devServer && key === "performance" ? asDevServerInconclusive(regression) : regression);
125901
126200
  }
125902
126201
  }
125903
126202
  const hasScores = pairs.some((p) => p.prod.lhScores && p.cand.lhScores);
125904
126203
  return {
125905
126204
  name: "lighthouse-scores",
125906
- status: !hasScores ? "skipped" : issues.length > 0 ? "fail" : "pass",
126205
+ status: !hasScores ? "skipped" : issues.some((i) => !i.inconclusive) ? "fail" : issues.length > 0 ? "warn" : "pass",
125907
126206
  severity: "medium",
125908
126207
  durationMs: Date.now() - start,
125909
126208
  summary: !hasScores ? "Sem scores Lighthouse (rode sem --no-lighthouse)" : `${pairs.length} página(s), ${issues.length} regressão(ões) de categoria`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.35.32",
3
+ "version": "0.35.34",
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",