@decocms/parity 0.35.33 → 0.35.35
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 -1
- package/CHANGELOG.md +22 -0
- package/dist/cli.js +597 -40
- package/package.json +1 -1
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,28 @@ 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
|
+
|
|
25
|
+
* **`parity capacity`** answers "may one more heavy agent start on this machine now, and how many
|
|
26
|
+
more?" so the orchestrator admits parallel fixers/porters by what the machine can carry instead
|
|
27
|
+
of a fixed 5. Measures cores, 1-minute load, available memory (macOS `vm_stat`, because
|
|
28
|
+
`os.freemem()` reads 2.0 GB where 5.3 GB is available; Linux `MemAvailable`, cgroup-capped),
|
|
29
|
+
swap and free disk, then `slots = min(max, memory, cpu, swap, disk)`. An unreadable input caps at
|
|
30
|
+
1 and is named, never read as headroom. Read-only; exit 0 admit, 1 no headroom, 2 could not
|
|
31
|
+
measure enough. The orchestrator checks it before each additional agent and removes a fixer's
|
|
32
|
+
worktree once its PR is merged or closed (disk was the binding constraint).
|
|
33
|
+
|
|
12
34
|
* **`first-viewport-ssr` check (html module)** answers "is what the user sees in the first viewport
|
|
13
35
|
already in the server response, or does it arrive later?". A deferred header (a skeleton in the
|
|
14
36
|
server HTML that client JS fills in) passed `ssr-no-js` (the rest of the page carried the text)
|
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 chalk50 from "chalk";
|
|
75783
75783
|
import { Command, InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
75784
75784
|
|
|
75785
75785
|
// src/commands/ab-detect.ts
|
|
@@ -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,
|
|
@@ -79020,6 +79052,14 @@ function hasDialogLikeMarkup(page) {
|
|
|
79020
79052
|
|
|
79021
79053
|
// src/checks/favicon-parity.ts
|
|
79022
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
|
|
79023
79063
|
async function faviconParity(ctx) {
|
|
79024
79064
|
const start = Date.now();
|
|
79025
79065
|
const issues = [];
|
|
@@ -79098,7 +79138,7 @@ async function hashUrl(href, base) {
|
|
|
79098
79138
|
return null;
|
|
79099
79139
|
}
|
|
79100
79140
|
try {
|
|
79101
|
-
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)) });
|
|
79102
79142
|
if (!res.ok)
|
|
79103
79143
|
return null;
|
|
79104
79144
|
const buf = await res.arrayBuffer();
|
|
@@ -79398,7 +79438,7 @@ async function probeLinks(urls) {
|
|
|
79398
79438
|
const res = await fetch(url, {
|
|
79399
79439
|
method: "HEAD",
|
|
79400
79440
|
redirect: "follow",
|
|
79401
|
-
signal: AbortSignal.timeout(8000)
|
|
79441
|
+
signal: AbortSignal.timeout(probeTimeoutMs(url, 8000))
|
|
79402
79442
|
});
|
|
79403
79443
|
return { url, status: res.status, durationMs: Date.now() - t };
|
|
79404
79444
|
} catch {
|
|
@@ -79949,6 +79989,39 @@ function extractSectionIds(entries) {
|
|
|
79949
79989
|
return out;
|
|
79950
79990
|
}
|
|
79951
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
|
+
|
|
79952
80025
|
// src/checks/lib/html-snapshot.ts
|
|
79953
80026
|
function htmlUnread(page) {
|
|
79954
80027
|
return page.htmlSnapshotFailed === true || !page.html;
|
|
@@ -80409,7 +80482,7 @@ async function probeRoutes(links, base) {
|
|
|
80409
80482
|
const res = await fetch(url, {
|
|
80410
80483
|
method: "HEAD",
|
|
80411
80484
|
redirect: "follow",
|
|
80412
|
-
signal: AbortSignal.timeout(8000)
|
|
80485
|
+
signal: AbortSignal.timeout(probeTimeoutMs(url, 8000))
|
|
80413
80486
|
});
|
|
80414
80487
|
return { path, status: res.status };
|
|
80415
80488
|
} catch {
|
|
@@ -81726,7 +81799,7 @@ async function fetchPlpProducts(url) {
|
|
|
81726
81799
|
headers: {
|
|
81727
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"
|
|
81728
81801
|
},
|
|
81729
|
-
signal: AbortSignal.timeout(15000)
|
|
81802
|
+
signal: AbortSignal.timeout(probeTimeoutMs(url, 15000))
|
|
81730
81803
|
});
|
|
81731
81804
|
if (res.status !== 200) {
|
|
81732
81805
|
return { status: res.status, productPaths: [] };
|
|
@@ -81806,7 +81879,7 @@ async function discoverPlpFromHome(homeUrl) {
|
|
|
81806
81879
|
headers: {
|
|
81807
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"
|
|
81808
81881
|
},
|
|
81809
|
-
signal: AbortSignal.timeout(15000)
|
|
81882
|
+
signal: AbortSignal.timeout(probeTimeoutMs(homeUrl, 15000))
|
|
81810
81883
|
});
|
|
81811
81884
|
if (!res.ok)
|
|
81812
81885
|
return null;
|
|
@@ -81979,7 +82052,7 @@ async function fetchOrderedHrefs(url) {
|
|
|
81979
82052
|
headers: {
|
|
81980
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"
|
|
81981
82054
|
},
|
|
81982
|
-
signal: AbortSignal.timeout(15000)
|
|
82055
|
+
signal: AbortSignal.timeout(probeTimeoutMs(url, 15000))
|
|
81983
82056
|
});
|
|
81984
82057
|
if (res.status !== 200)
|
|
81985
82058
|
return { status: res.status, hrefs: [] };
|
|
@@ -83566,7 +83639,7 @@ async function ssrNoJs(ctx) {
|
|
|
83566
83639
|
}
|
|
83567
83640
|
async function fetchSsrText(url) {
|
|
83568
83641
|
try {
|
|
83569
|
-
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)) });
|
|
83570
83643
|
if (!res.ok)
|
|
83571
83644
|
return null;
|
|
83572
83645
|
const html = await res.text();
|
|
@@ -91148,7 +91221,7 @@ async function runAllChecks(ctx, outResults, checkFilter) {
|
|
|
91148
91221
|
await Promise.all(checksToRun.map(async (check, i) => {
|
|
91149
91222
|
const start = Date.now();
|
|
91150
91223
|
try {
|
|
91151
|
-
const r = await check(ctx);
|
|
91224
|
+
const r = await withHealthyCand(check)(ctx);
|
|
91152
91225
|
push({ ...r, durationMs: r.durationMs || Date.now() - start }, i);
|
|
91153
91226
|
} catch (err) {
|
|
91154
91227
|
push({
|
|
@@ -91491,6 +91564,7 @@ var PageCapture = z2.object({
|
|
|
91491
91564
|
pass: z2.enum(["extra", "visual"]).optional(),
|
|
91492
91565
|
variant: VariantFingerprint.optional(),
|
|
91493
91566
|
retried: z2.boolean().optional(),
|
|
91567
|
+
candDegraded: z2.string().optional(),
|
|
91494
91568
|
clickProbe: ClickProbe.optional(),
|
|
91495
91569
|
firstViewport: FirstViewportProbe.optional()
|
|
91496
91570
|
});
|
|
@@ -91845,6 +91919,17 @@ var Run = z2.object({
|
|
|
91845
91919
|
partial: z2.boolean().optional(),
|
|
91846
91920
|
partialReason: z2.string().optional(),
|
|
91847
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(),
|
|
91848
91933
|
pinned: z2.object({
|
|
91849
91934
|
prod: z2.object({ cookies: z2.array(z2.string()), headers: z2.array(z2.string()) }),
|
|
91850
91935
|
cand: z2.object({ cookies: z2.array(z2.string()), headers: z2.array(z2.string()) })
|
|
@@ -119480,7 +119565,7 @@ async function primeSequentially(urls, primed, prime) {
|
|
|
119480
119565
|
}
|
|
119481
119566
|
return { attempted: urls.length, failed, totalMs: Date.now() - start };
|
|
119482
119567
|
}
|
|
119483
|
-
async function primeCandUrls(browser, urls, primed, ctxOpts) {
|
|
119568
|
+
async function primeCandUrls(browser, urls, primed, ctxOpts, baselines) {
|
|
119484
119569
|
if (urls.length === 0)
|
|
119485
119570
|
return { attempted: 0, failed: [], totalMs: 0 };
|
|
119486
119571
|
const ctx = await newContext(browser, { cohortCookieValue: "control", ...ctxOpts });
|
|
@@ -119488,7 +119573,12 @@ async function primeCandUrls(browser, urls, primed, ctxOpts) {
|
|
|
119488
119573
|
return await primeSequentially(urls, primed, async (url) => {
|
|
119489
119574
|
const page = await ctx.newPage();
|
|
119490
119575
|
try {
|
|
119491
|
-
|
|
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
|
+
}
|
|
119492
119582
|
await page.waitForLoadState("load", { timeout: PRIME_LOAD_MS }).catch(() => {
|
|
119493
119583
|
return;
|
|
119494
119584
|
});
|
|
@@ -119546,6 +119636,17 @@ function detectRunCaveats(input) {
|
|
|
119546
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."
|
|
119547
119637
|
});
|
|
119548
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
|
+
}
|
|
119549
119650
|
if (isLocalhost(input.prodUrl)) {
|
|
119550
119651
|
out.push({
|
|
119551
119652
|
id: "prod-dev-server",
|
|
@@ -119697,6 +119798,113 @@ function describePin(pin) {
|
|
|
119697
119798
|
].join(", ");
|
|
119698
119799
|
}
|
|
119699
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
|
+
|
|
119700
119908
|
// src/util/timing.ts
|
|
119701
119909
|
async function withTiming(fn) {
|
|
119702
119910
|
const start = performance.now();
|
|
@@ -120271,6 +120479,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120271
120479
|
}
|
|
120272
120480
|
const primeEnabled = opts.primeCand !== false && isLocalhost(opts.cand);
|
|
120273
120481
|
const primed = new Set;
|
|
120482
|
+
const candBaselines = new Map;
|
|
120274
120483
|
const primeAcc = { attempted: 0, failed: [], totalMs: 0 };
|
|
120275
120484
|
const candRetry = { retried: 0, recovered: 0 };
|
|
120276
120485
|
const retrying = new Set;
|
|
@@ -120297,7 +120506,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120297
120506
|
viewport: viewports[0],
|
|
120298
120507
|
cookies: pins.cand.cookies,
|
|
120299
120508
|
headers: pins.cand.headers
|
|
120300
|
-
});
|
|
120509
|
+
}, candBaselines);
|
|
120301
120510
|
primeAcc.attempted += r.attempted;
|
|
120302
120511
|
primeAcc.failed.push(...r.failed);
|
|
120303
120512
|
primeAcc.totalMs += r.totalMs;
|
|
@@ -120600,7 +120809,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120600
120809
|
extraSpinner.text = `[vitals extras] ${done}/${tasks.length} (último: ${task.path})`;
|
|
120601
120810
|
}
|
|
120602
120811
|
};
|
|
120603
|
-
await
|
|
120812
|
+
await runCapturePool(tasks, opts.cand, runTask);
|
|
120604
120813
|
await retryColdCand("extra", tasks, runTask);
|
|
120605
120814
|
vitalsHb.stop();
|
|
120606
120815
|
extraSpinner.succeed(`+${extraPaths.length} página(s) com vitals`);
|
|
@@ -120697,7 +120906,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120697
120906
|
visualSpinner.text = `[visual] ${done}/${tasks.length} (último: ${task.path})`;
|
|
120698
120907
|
}
|
|
120699
120908
|
};
|
|
120700
|
-
await
|
|
120909
|
+
await runCapturePool(tasks, opts.cand, runTask);
|
|
120701
120910
|
await retryColdCand("visual", tasks, runTask);
|
|
120702
120911
|
visualHb.stop();
|
|
120703
120912
|
visualSpinner.succeed(`Visual diff: ${tasks.length} screenshot(s) capturado(s)`);
|
|
@@ -120749,6 +120958,15 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120749
120958
|
viewports,
|
|
120750
120959
|
candIsProduction: opts.candIsProduction
|
|
120751
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
|
+
}
|
|
120752
120970
|
let recordedOk = false;
|
|
120753
120971
|
let goldenStale = [];
|
|
120754
120972
|
if (opts.record) {
|
|
@@ -120901,8 +121119,10 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
120901
121119
|
llmEnabled: llmStillAvailable,
|
|
120902
121120
|
candIsProduction: opts.candIsProduction,
|
|
120903
121121
|
prodPinned: !isEmptyPin(pins.prod),
|
|
120904
|
-
warmLoads: warmLoadsNow()
|
|
121122
|
+
warmLoads: warmLoadsNow(),
|
|
121123
|
+
candHealth
|
|
120905
121124
|
})),
|
|
121125
|
+
candHealth,
|
|
120906
121126
|
pinned: isEmptyPin(pins.prod) && isEmptyPin(pins.cand) ? undefined : { prod: pinNames(pins.prod), cand: pinNames(pins.cand) },
|
|
120907
121127
|
pagePairs,
|
|
120908
121128
|
golden: goldenRec ? goldenReportField(resolve21(opts.golden), goldenRec.meta, goldenStale) : undefined
|
|
@@ -121124,6 +121344,15 @@ function formatPagePairTable(rows) {
|
|
|
121124
121344
|
}).join(`
|
|
121125
121345
|
`);
|
|
121126
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
|
+
}
|
|
121127
121356
|
async function runWithConcurrency2(items, workers, fn) {
|
|
121128
121357
|
let next = 0;
|
|
121129
121358
|
await Promise.all(Array.from({ length: workers }, async () => {
|
|
@@ -123418,11 +123647,11 @@ function L2(pt, en, lang) {
|
|
|
123418
123647
|
const initial = lang === "pt" ? pt : en;
|
|
123419
123648
|
return `<span class="i18n" data-pt="${esc3(pt)}" data-en="${esc3(en)}">${esc3(initial)}</span>`;
|
|
123420
123649
|
}
|
|
123421
|
-
function
|
|
123650
|
+
function T3(text, lang) {
|
|
123422
123651
|
return L2(text.pt, text.en, lang);
|
|
123423
123652
|
}
|
|
123424
123653
|
function tiles(items, lang) {
|
|
123425
|
-
const cells = items.map((t) => `<div class="tile"><div class="tile-val ${TONE_CLASS[t.tone]}">${esc3(t.value)}</div><div class="tile-label">${
|
|
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("");
|
|
123426
123655
|
return `<div class="stat-grid">${cells}</div>`;
|
|
123427
123656
|
}
|
|
123428
123657
|
function page(eyebrow, title, body, note) {
|
|
@@ -125313,11 +125542,336 @@ async function studioCommentCommand(opts, call = callTool2) {
|
|
|
125313
125542
|
}
|
|
125314
125543
|
}
|
|
125315
125544
|
|
|
125316
|
-
// src/commands/
|
|
125317
|
-
import {
|
|
125318
|
-
import {
|
|
125545
|
+
// src/commands/capacity.ts
|
|
125546
|
+
import { execFileSync as execFileSync7 } from "node:child_process";
|
|
125547
|
+
import { readFileSync as readFileSync46, statfsSync } from "node:fs";
|
|
125548
|
+
import os from "node:os";
|
|
125319
125549
|
import { resolve as resolve24 } from "node:path";
|
|
125320
125550
|
import chalk46 from "chalk";
|
|
125551
|
+
|
|
125552
|
+
// src/commands/capacity-tolerances.ts
|
|
125553
|
+
var CAPACITY_DEFAULTS = {
|
|
125554
|
+
perAgentGB: {
|
|
125555
|
+
value: 1.5,
|
|
125556
|
+
unit: "GB",
|
|
125557
|
+
basis: "assumed",
|
|
125558
|
+
note: "Resident memory of one agent's dev server + headless Chromium + a gate run. Not measured per agent: derived from 3 agents tipping a 16 GB machine into swap."
|
|
125559
|
+
},
|
|
125560
|
+
reserveGB: {
|
|
125561
|
+
value: 2,
|
|
125562
|
+
unit: "GB",
|
|
125563
|
+
basis: "assumed",
|
|
125564
|
+
note: "Memory left for the OS, the editor and the orchestrator itself; never handed to an agent."
|
|
125565
|
+
},
|
|
125566
|
+
perAgentCores: {
|
|
125567
|
+
value: 2,
|
|
125568
|
+
unit: "cores",
|
|
125569
|
+
basis: "assumed",
|
|
125570
|
+
note: "A dev server plus a build or test run keep about two cores busy. Load 11.8 on 10 cores with three agents is ~4 per agent at the peak; 2 is the sustained figure."
|
|
125571
|
+
},
|
|
125572
|
+
reserveCores: {
|
|
125573
|
+
value: 0,
|
|
125574
|
+
unit: "cores",
|
|
125575
|
+
basis: "assumed",
|
|
125576
|
+
note: "The 1-minute load average already contains whatever else runs on the machine, so no extra reserve."
|
|
125577
|
+
},
|
|
125578
|
+
swapThreshold: {
|
|
125579
|
+
value: 0.75,
|
|
125580
|
+
unit: "ratio (0-1)",
|
|
125581
|
+
basis: "assumed",
|
|
125582
|
+
note: "Swap used / swap total above this means the machine is already paging: free RAM figures stop meaning what they say."
|
|
125583
|
+
},
|
|
125584
|
+
swapCap: {
|
|
125585
|
+
value: 2,
|
|
125586
|
+
unit: "agents",
|
|
125587
|
+
basis: "assumed",
|
|
125588
|
+
note: "Slots allowed while swap is above the threshold. At 90% swap the measured case still ran three agents, slowly."
|
|
125589
|
+
},
|
|
125590
|
+
perAgentDiskGB: {
|
|
125591
|
+
value: 1,
|
|
125592
|
+
unit: "GB",
|
|
125593
|
+
basis: "assumed",
|
|
125594
|
+
note: "One worktree (~540 MB measured) plus its node_modules churn and a capture (~180 MB measured)."
|
|
125595
|
+
},
|
|
125596
|
+
reserveDiskGB: {
|
|
125597
|
+
value: 3,
|
|
125598
|
+
unit: "GB",
|
|
125599
|
+
basis: "assumed",
|
|
125600
|
+
note: "Headroom so a full disk does not corrupt a git operation or a capture mid-write."
|
|
125601
|
+
},
|
|
125602
|
+
maxParallel: {
|
|
125603
|
+
value: 5,
|
|
125604
|
+
unit: "agents",
|
|
125605
|
+
basis: "assumed",
|
|
125606
|
+
note: "The orchestrator's ceiling ('up to 5 per round'); `budget.maxParallel` in the state file overrides it via --max."
|
|
125607
|
+
},
|
|
125608
|
+
unknownCap: {
|
|
125609
|
+
value: 1,
|
|
125610
|
+
unit: "agents",
|
|
125611
|
+
basis: "assumed",
|
|
125612
|
+
note: "What an input that could not be read contributes. Never headroom: the caller runs one agent at a time."
|
|
125613
|
+
}
|
|
125614
|
+
};
|
|
125615
|
+
|
|
125616
|
+
// src/commands/capacity.ts
|
|
125617
|
+
var GB = 2 ** 30;
|
|
125618
|
+
var defaultParams = () => ({
|
|
125619
|
+
perAgentGB: CAPACITY_DEFAULTS.perAgentGB.value,
|
|
125620
|
+
reserveGB: CAPACITY_DEFAULTS.reserveGB.value,
|
|
125621
|
+
perAgentCores: CAPACITY_DEFAULTS.perAgentCores.value,
|
|
125622
|
+
reserveCores: CAPACITY_DEFAULTS.reserveCores.value,
|
|
125623
|
+
swapThreshold: CAPACITY_DEFAULTS.swapThreshold.value,
|
|
125624
|
+
swapCap: CAPACITY_DEFAULTS.swapCap.value,
|
|
125625
|
+
perAgentDiskGB: CAPACITY_DEFAULTS.perAgentDiskGB.value,
|
|
125626
|
+
reserveDiskGB: CAPACITY_DEFAULTS.reserveDiskGB.value,
|
|
125627
|
+
maxParallel: CAPACITY_DEFAULTS.maxParallel.value
|
|
125628
|
+
});
|
|
125629
|
+
function decideCapacity(inputs, params = defaultParams(), running) {
|
|
125630
|
+
const p = params;
|
|
125631
|
+
const unknown = [];
|
|
125632
|
+
const cap = CAPACITY_DEFAULTS.unknownCap.value;
|
|
125633
|
+
const term = (names, f) => {
|
|
125634
|
+
const missing = names.filter((n) => inputs[n] === null);
|
|
125635
|
+
unknown.push(...missing);
|
|
125636
|
+
return missing.length ? cap : Math.floor(f());
|
|
125637
|
+
};
|
|
125638
|
+
const memSlots = term(["availableGB"], () => (inputs.availableGB - p.reserveGB) / p.perAgentGB);
|
|
125639
|
+
const cpuSlots = term(["cores", "load1"], () => (inputs.cores - inputs.load1 - p.reserveCores) / p.perAgentCores);
|
|
125640
|
+
const diskSlots = term(["freeDiskGB"], () => (inputs.freeDiskGB - p.reserveDiskGB) / p.perAgentDiskGB);
|
|
125641
|
+
let swapCap = null;
|
|
125642
|
+
if (inputs.swapUsedGB === null || inputs.swapTotalGB === null) {
|
|
125643
|
+
unknown.push(...["swapUsedGB", "swapTotalGB"].filter((n) => inputs[n] === null));
|
|
125644
|
+
swapCap = cap;
|
|
125645
|
+
} else if (inputs.swapTotalGB > 0 && inputs.swapUsedGB / inputs.swapTotalGB > p.swapThreshold) {
|
|
125646
|
+
swapCap = p.swapCap;
|
|
125647
|
+
}
|
|
125648
|
+
const swapU = inputs.swapUsedGB === null || inputs.swapTotalGB === null;
|
|
125649
|
+
const cands = [
|
|
125650
|
+
["swap", swapCap ?? Number.POSITIVE_INFINITY, swapU],
|
|
125651
|
+
["memory", memSlots, inputs.availableGB === null],
|
|
125652
|
+
["cpu", cpuSlots, inputs.cores === null || inputs.load1 === null],
|
|
125653
|
+
["disk", diskSlots, inputs.freeDiskGB === null],
|
|
125654
|
+
["max", p.maxParallel, false]
|
|
125655
|
+
];
|
|
125656
|
+
let limitedBy = "max";
|
|
125657
|
+
let best = Number.POSITIVE_INFINITY;
|
|
125658
|
+
let bestUnknown = false;
|
|
125659
|
+
for (const [name, v, isUnknown] of cands) {
|
|
125660
|
+
if (v < best || v === best && isUnknown && !bestUnknown) {
|
|
125661
|
+
[limitedBy, best, bestUnknown] = [isUnknown ? "unknown" : name, v, isUnknown];
|
|
125662
|
+
}
|
|
125663
|
+
}
|
|
125664
|
+
const slots = Math.max(0, best);
|
|
125665
|
+
const report = {
|
|
125666
|
+
slots,
|
|
125667
|
+
admit: slots >= 1,
|
|
125668
|
+
limitedBy,
|
|
125669
|
+
inputs,
|
|
125670
|
+
terms: { memSlots, cpuSlots, swapCap, diskSlots },
|
|
125671
|
+
unknown,
|
|
125672
|
+
advice: ""
|
|
125673
|
+
};
|
|
125674
|
+
if (running !== undefined)
|
|
125675
|
+
report.running = running;
|
|
125676
|
+
report.advice = adviceFor(report);
|
|
125677
|
+
return report;
|
|
125678
|
+
}
|
|
125679
|
+
function adviceFor(r) {
|
|
125680
|
+
if (r.slots === 0) {
|
|
125681
|
+
return `no headroom (${r.limitedBy}): wait for a running agent to finish, then re-check`;
|
|
125682
|
+
}
|
|
125683
|
+
if (r.unknown.length) {
|
|
125684
|
+
return `could not read ${r.unknown.join(", ")}: run one agent at a time`;
|
|
125685
|
+
}
|
|
125686
|
+
return `room for ${r.slots} more agent(s) now (limited by ${r.limitedBy}); re-check before each start`;
|
|
125687
|
+
}
|
|
125688
|
+
function capacityExitCode(r) {
|
|
125689
|
+
if (r.slots < 1)
|
|
125690
|
+
return 1;
|
|
125691
|
+
return r.unknown.length ? 2 : 0;
|
|
125692
|
+
}
|
|
125693
|
+
function parseVmStat(text) {
|
|
125694
|
+
const size = /page size of (\d+) bytes/.exec(text)?.[1];
|
|
125695
|
+
const pages = (label) => {
|
|
125696
|
+
const m = new RegExp(`^${label}:\\s+(\\d+)\\.`, "m").exec(text);
|
|
125697
|
+
return m ? Number(m[1]) : null;
|
|
125698
|
+
};
|
|
125699
|
+
const free = pages("Pages free");
|
|
125700
|
+
if (!size || free === null)
|
|
125701
|
+
return null;
|
|
125702
|
+
const purgeable = pages("Pages purgeable") ?? 0;
|
|
125703
|
+
const fileBacked = pages("File-backed pages");
|
|
125704
|
+
const reclaimable = fileBacked !== null ? fileBacked : (pages("Pages speculative") ?? 0) + (pages("Pages inactive") ?? 0);
|
|
125705
|
+
return (free + reclaimable + purgeable) * Number(size);
|
|
125706
|
+
}
|
|
125707
|
+
function parseSwapUsage(text) {
|
|
125708
|
+
const grab = (k) => {
|
|
125709
|
+
const m = new RegExp(`${k} = ([\\d.]+)([KMGT])`).exec(text);
|
|
125710
|
+
if (!m)
|
|
125711
|
+
return null;
|
|
125712
|
+
return Number(m[1]) * 1024 ** ("KMGT".indexOf(m[2]) + 1);
|
|
125713
|
+
};
|
|
125714
|
+
const total = grab("total");
|
|
125715
|
+
const used = grab("used");
|
|
125716
|
+
return total === null || used === null ? null : { usedBytes: used, totalBytes: total };
|
|
125717
|
+
}
|
|
125718
|
+
var kb = (text, key) => {
|
|
125719
|
+
const m = new RegExp(`^${key}:\\s+(\\d+) kB`, "m").exec(text);
|
|
125720
|
+
return m ? Number(m[1]) * 1024 : null;
|
|
125721
|
+
};
|
|
125722
|
+
function parseMeminfo(text, cgroup) {
|
|
125723
|
+
let available = kb(text, "MemAvailable");
|
|
125724
|
+
if (available !== null && cgroup?.limit != null && cgroup.current != null) {
|
|
125725
|
+
available = Math.min(available, Math.max(0, cgroup.limit - cgroup.current));
|
|
125726
|
+
}
|
|
125727
|
+
const total = kb(text, "SwapTotal");
|
|
125728
|
+
const free = kb(text, "SwapFree");
|
|
125729
|
+
return {
|
|
125730
|
+
availableBytes: available,
|
|
125731
|
+
swapTotalBytes: total,
|
|
125732
|
+
swapUsedBytes: total !== null && free !== null ? total - free : null
|
|
125733
|
+
};
|
|
125734
|
+
}
|
|
125735
|
+
var realProbe = {
|
|
125736
|
+
platform: process.platform,
|
|
125737
|
+
readFile: (p) => {
|
|
125738
|
+
try {
|
|
125739
|
+
return readFileSync46(p, "utf8");
|
|
125740
|
+
} catch {
|
|
125741
|
+
return null;
|
|
125742
|
+
}
|
|
125743
|
+
},
|
|
125744
|
+
run: (cmd, args) => {
|
|
125745
|
+
try {
|
|
125746
|
+
return execFileSync7(cmd, args, {
|
|
125747
|
+
encoding: "utf8",
|
|
125748
|
+
timeout: 5000,
|
|
125749
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
125750
|
+
});
|
|
125751
|
+
} catch {
|
|
125752
|
+
return null;
|
|
125753
|
+
}
|
|
125754
|
+
},
|
|
125755
|
+
freeDiskBytes: (dir) => {
|
|
125756
|
+
try {
|
|
125757
|
+
const s = statfsSync(dir);
|
|
125758
|
+
return s.bavail * s.bsize;
|
|
125759
|
+
} catch {
|
|
125760
|
+
return null;
|
|
125761
|
+
}
|
|
125762
|
+
},
|
|
125763
|
+
cores: () => os.availableParallelism(),
|
|
125764
|
+
loadavg: () => os.loadavg(),
|
|
125765
|
+
freemem: () => os.freemem()
|
|
125766
|
+
};
|
|
125767
|
+
var toGB = (b) => b === null ? null : b / GB;
|
|
125768
|
+
function measure(dir, probe = realProbe) {
|
|
125769
|
+
let availableBytes = null;
|
|
125770
|
+
let swapUsed = null;
|
|
125771
|
+
let swapTotal = null;
|
|
125772
|
+
if (probe.platform === "darwin") {
|
|
125773
|
+
const vm = probe.run("vm_stat", []);
|
|
125774
|
+
availableBytes = vm ? parseVmStat(vm) : null;
|
|
125775
|
+
const sw = probe.run("sysctl", ["vm.swapusage"]);
|
|
125776
|
+
const s = sw ? parseSwapUsage(sw) : null;
|
|
125777
|
+
swapUsed = s?.usedBytes ?? null;
|
|
125778
|
+
swapTotal = s?.totalBytes ?? null;
|
|
125779
|
+
} else if (probe.platform === "linux") {
|
|
125780
|
+
const mi = probe.readFile("/proc/meminfo");
|
|
125781
|
+
if (mi) {
|
|
125782
|
+
const num = (p) => {
|
|
125783
|
+
const t = probe.readFile(p)?.trim();
|
|
125784
|
+
return t && /^\d+$/.test(t) ? Number(t) : null;
|
|
125785
|
+
};
|
|
125786
|
+
const m = parseMeminfo(mi, {
|
|
125787
|
+
limit: num("/sys/fs/cgroup/memory.max"),
|
|
125788
|
+
current: num("/sys/fs/cgroup/memory.current")
|
|
125789
|
+
});
|
|
125790
|
+
availableBytes = m.availableBytes;
|
|
125791
|
+
swapUsed = m.swapUsedBytes;
|
|
125792
|
+
swapTotal = m.swapTotalBytes;
|
|
125793
|
+
}
|
|
125794
|
+
} else if (probe.platform === "win32") {
|
|
125795
|
+
availableBytes = probe.freemem();
|
|
125796
|
+
}
|
|
125797
|
+
const load1 = probe.platform === "win32" ? null : probe.loadavg()[0] ?? null;
|
|
125798
|
+
const disk = probe.freeDiskBytes(dir);
|
|
125799
|
+
return {
|
|
125800
|
+
cores: probe.cores() || null,
|
|
125801
|
+
load1,
|
|
125802
|
+
availableGB: toGB(availableBytes),
|
|
125803
|
+
swapUsedGB: toGB(swapUsed),
|
|
125804
|
+
swapTotalGB: toGB(swapTotal),
|
|
125805
|
+
freeDiskGB: toGB(disk)
|
|
125806
|
+
};
|
|
125807
|
+
}
|
|
125808
|
+
var FLAG_TO_PARAM = [
|
|
125809
|
+
["max", "maxParallel", 0],
|
|
125810
|
+
["perAgentGb", "perAgentGB", Number.MIN_VALUE],
|
|
125811
|
+
["reserveGb", "reserveGB", 0],
|
|
125812
|
+
["perAgentCores", "perAgentCores", Number.MIN_VALUE],
|
|
125813
|
+
["reserveCores", "reserveCores", 0],
|
|
125814
|
+
["swapThreshold", "swapThreshold", 0],
|
|
125815
|
+
["swapCap", "swapCap", 0],
|
|
125816
|
+
["perAgentDiskGb", "perAgentDiskGB", Number.MIN_VALUE],
|
|
125817
|
+
["reserveDiskGb", "reserveDiskGB", 0]
|
|
125818
|
+
];
|
|
125819
|
+
function paramsFromFlags(flags) {
|
|
125820
|
+
const params = defaultParams();
|
|
125821
|
+
for (const [flag, key, min] of FLAG_TO_PARAM) {
|
|
125822
|
+
const raw = flags[flag];
|
|
125823
|
+
if (raw === undefined)
|
|
125824
|
+
continue;
|
|
125825
|
+
const n = Number(raw);
|
|
125826
|
+
if (raw.trim() === "" || !Number.isFinite(n) || n < min) {
|
|
125827
|
+
return {
|
|
125828
|
+
error: `--${flag.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)} "${raw}" is not a valid number`
|
|
125829
|
+
};
|
|
125830
|
+
}
|
|
125831
|
+
params[key] = n;
|
|
125832
|
+
}
|
|
125833
|
+
return params;
|
|
125834
|
+
}
|
|
125835
|
+
function capacityCommand(flags, probe = realProbe) {
|
|
125836
|
+
const params = paramsFromFlags(flags);
|
|
125837
|
+
let running;
|
|
125838
|
+
if (flags.running !== undefined) {
|
|
125839
|
+
const n = Number(flags.running);
|
|
125840
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
125841
|
+
return fail3(flags, `--running "${flags.running}" is not a non-negative integer`);
|
|
125842
|
+
}
|
|
125843
|
+
running = n;
|
|
125844
|
+
}
|
|
125845
|
+
if ("error" in params)
|
|
125846
|
+
return fail3(flags, params.error);
|
|
125847
|
+
const r = decideCapacity(measure(resolve24(flags.dir ?? "."), probe), params, running);
|
|
125848
|
+
const code = capacityExitCode(r);
|
|
125849
|
+
if (flags.json) {
|
|
125850
|
+
console.log(JSON.stringify(r));
|
|
125851
|
+
} else {
|
|
125852
|
+
const f = (n, u) => n === null ? chalk46.yellow("unknown") : `${n.toFixed(1)} ${u}`.trim();
|
|
125853
|
+
const i = r.inputs;
|
|
125854
|
+
console.log(` machine ${f(i.cores, "cores")}, load1 ${f(i.load1, "")}, memory ${f(i.availableGB, "GB")} available, swap ${f(i.swapUsedGB, "")}/${f(i.swapTotalGB, "GB")}, disk ${f(i.freeDiskGB, "GB")} free`);
|
|
125855
|
+
console.log(` slots ${r.slots} (memory ${r.terms.memSlots}, cpu ${r.terms.cpuSlots}, swap ${r.terms.swapCap ?? "-"}, disk ${r.terms.diskSlots}, max ${params.maxParallel}; limited by ${r.limitedBy})`);
|
|
125856
|
+
if (r.running !== undefined)
|
|
125857
|
+
console.log(` running ${r.running} (already in the load; not subtracted)`);
|
|
125858
|
+
console.log(` ${code === 0 ? chalk46.green(r.advice) : code === 1 ? chalk46.red(r.advice) : chalk46.yellow(r.advice)}`);
|
|
125859
|
+
}
|
|
125860
|
+
return code;
|
|
125861
|
+
}
|
|
125862
|
+
function fail3(flags, message) {
|
|
125863
|
+
if (flags.json)
|
|
125864
|
+
console.log(JSON.stringify({ error: { code: "bad_flag", message } }));
|
|
125865
|
+
else
|
|
125866
|
+
console.error(chalk46.red(` ${message}`));
|
|
125867
|
+
return 2;
|
|
125868
|
+
}
|
|
125869
|
+
|
|
125870
|
+
// src/commands/drift.ts
|
|
125871
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
125872
|
+
import { existsSync as existsSync41, readFileSync as readFileSync47 } from "node:fs";
|
|
125873
|
+
import { resolve as resolve25 } from "node:path";
|
|
125874
|
+
import chalk47 from "chalk";
|
|
125321
125875
|
var DRIFT_EXCLUDES = [":!.deco"];
|
|
125322
125876
|
var SHA_RE = /^[0-9a-f]{7,64}$/i;
|
|
125323
125877
|
function resolveDriftInputs(state, flags) {
|
|
@@ -125506,7 +126060,7 @@ function loadState(path) {
|
|
|
125506
126060
|
if (!existsSync41(path))
|
|
125507
126061
|
return null;
|
|
125508
126062
|
try {
|
|
125509
|
-
return JSON.parse(
|
|
126063
|
+
return JSON.parse(readFileSync47(path, "utf8"));
|
|
125510
126064
|
} catch (err) {
|
|
125511
126065
|
return { error: { code: "state_unreadable", message: `${path}: ${err.message}` } };
|
|
125512
126066
|
}
|
|
@@ -125514,7 +126068,7 @@ function loadState(path) {
|
|
|
125514
126068
|
function runDrift(flags) {
|
|
125515
126069
|
let state = null;
|
|
125516
126070
|
if (!(flags.source && flags.base)) {
|
|
125517
|
-
const loaded = loadState(
|
|
126071
|
+
const loaded = loadState(resolve25(flags.state ?? ".parity/migration.json"));
|
|
125518
126072
|
if (loaded && "error" in loaded)
|
|
125519
126073
|
return loaded;
|
|
125520
126074
|
state = loaded;
|
|
@@ -125530,7 +126084,7 @@ function driftCommand(flags) {
|
|
|
125530
126084
|
if (flags.json)
|
|
125531
126085
|
console.log(JSON.stringify({ error: r.error }));
|
|
125532
126086
|
else
|
|
125533
|
-
console.error(
|
|
126087
|
+
console.error(chalk47.red(` could not measure drift [${r.error.code}]: ${r.error.message}`));
|
|
125534
126088
|
return 2;
|
|
125535
126089
|
}
|
|
125536
126090
|
if (flags.json) {
|
|
@@ -125549,7 +126103,7 @@ function driftCommand(flags) {
|
|
|
125549
126103
|
}
|
|
125550
126104
|
|
|
125551
126105
|
// src/commands/variance.ts
|
|
125552
|
-
import
|
|
126106
|
+
import chalk48 from "chalk";
|
|
125553
126107
|
|
|
125554
126108
|
// src/diff/variance.ts
|
|
125555
126109
|
var uniq2 = (xs) => [...new Set(xs)];
|
|
@@ -125653,7 +126207,7 @@ function formatVariance(report, opts = {}) {
|
|
|
125653
126207
|
// src/commands/variance.ts
|
|
125654
126208
|
function varianceCommand(opts) {
|
|
125655
126209
|
if (opts.runIds.length < 2) {
|
|
125656
|
-
console.error(
|
|
126210
|
+
console.error(chalk48.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
|
|
125657
126211
|
return 2;
|
|
125658
126212
|
}
|
|
125659
126213
|
const budget = Number.parseFloat(opts.scoreBudget ?? "1");
|
|
@@ -125662,7 +126216,7 @@ function varianceCommand(opts) {
|
|
|
125662
126216
|
try {
|
|
125663
126217
|
runs.push(loadRun(opts.output, id));
|
|
125664
126218
|
} catch (err) {
|
|
125665
|
-
console.error(
|
|
126219
|
+
console.error(chalk48.red(` ✖ ${err.message}`));
|
|
125666
126220
|
return 2;
|
|
125667
126221
|
}
|
|
125668
126222
|
}
|
|
@@ -125671,7 +126225,7 @@ function varianceCommand(opts) {
|
|
|
125671
126225
|
console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
|
|
125672
126226
|
} else {
|
|
125673
126227
|
console.log("");
|
|
125674
|
-
console.log(
|
|
126228
|
+
console.log(chalk48.bold(" Score variance"));
|
|
125675
126229
|
for (const line of formatVariance(report, { scoreBudget: budget }).split(`
|
|
125676
126230
|
`)) {
|
|
125677
126231
|
console.log(` ${line}`);
|
|
@@ -125683,10 +126237,10 @@ function varianceCommand(opts) {
|
|
|
125683
126237
|
}
|
|
125684
126238
|
|
|
125685
126239
|
// src/commands/vitals.ts
|
|
125686
|
-
import { existsSync as existsSync42, readFileSync as
|
|
126240
|
+
import { existsSync as existsSync42, readFileSync as readFileSync48, writeFileSync as writeFileSync39 } from "node:fs";
|
|
125687
126241
|
import { availableParallelism } from "node:os";
|
|
125688
126242
|
import { join as join55 } from "node:path";
|
|
125689
|
-
import
|
|
126243
|
+
import chalk49 from "chalk";
|
|
125690
126244
|
import ora9 from "ora";
|
|
125691
126245
|
|
|
125692
126246
|
// src/checks/agentic-nav.ts
|
|
@@ -125994,10 +126548,10 @@ async function vitalsCommand(opts) {
|
|
|
125994
126548
|
const runId = newRunId();
|
|
125995
126549
|
const paths = createRunDir(opts.output, runId);
|
|
125996
126550
|
const t0 = Date.now();
|
|
125997
|
-
console.log(
|
|
126551
|
+
console.log(chalk49.bold(`
|
|
125998
126552
|
parity vitals ${runId}`));
|
|
125999
|
-
console.log(
|
|
126000
|
-
console.log(
|
|
126553
|
+
console.log(chalk49.dim(` prod: ${opts.prod}`));
|
|
126554
|
+
console.log(chalk49.dim(` cand: ${opts.cand}`));
|
|
126001
126555
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
126002
126556
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
126003
126557
|
if (pagePaths.length === 0) {
|
|
@@ -126029,7 +126583,7 @@ async function vitalsCommand(opts) {
|
|
|
126029
126583
|
completed++;
|
|
126030
126584
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
126031
126585
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
126032
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
126586
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk49.cyan("prod") : chalk49.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
126033
126587
|
}
|
|
126034
126588
|
});
|
|
126035
126589
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
@@ -126058,7 +126612,7 @@ async function vitalsCommand(opts) {
|
|
|
126058
126612
|
}
|
|
126059
126613
|
lhCompleted++;
|
|
126060
126614
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
126061
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
126615
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk49.cyan("prod") : chalk49.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
126062
126616
|
});
|
|
126063
126617
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
126064
126618
|
}
|
|
@@ -126136,8 +126690,8 @@ async function vitalsCommand(opts) {
|
|
|
126136
126690
|
`, "utf8");
|
|
126137
126691
|
printSummary9(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
126138
126692
|
console.log("");
|
|
126139
|
-
console.log(
|
|
126140
|
-
console.log(
|
|
126693
|
+
console.log(chalk49.dim(` → ${paths.reportHtml}`));
|
|
126694
|
+
console.log(chalk49.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
126141
126695
|
console.log("");
|
|
126142
126696
|
if (opts.open) {
|
|
126143
126697
|
const { default: open } = await import("open");
|
|
@@ -126230,14 +126784,14 @@ function parseUrlList(input) {
|
|
|
126230
126784
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
126231
126785
|
const path = input.replace(/^file:\/\//, "");
|
|
126232
126786
|
if (existsSync42(path)) {
|
|
126233
|
-
return
|
|
126787
|
+
return readFileSync48(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
126234
126788
|
}
|
|
126235
126789
|
}
|
|
126236
126790
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
126237
126791
|
}
|
|
126238
126792
|
function printSummary9(vitals, cache, scores, opportunities, agentic) {
|
|
126239
126793
|
console.log("");
|
|
126240
|
-
console.log(
|
|
126794
|
+
console.log(chalk49.bold(" Summary:"));
|
|
126241
126795
|
console.log(` ${vitals.summary}`);
|
|
126242
126796
|
console.log(` ${cache.summary}`);
|
|
126243
126797
|
if (scores.status !== "skipped")
|
|
@@ -126301,10 +126855,10 @@ sweep.addCommand(new Command("regress").description("Run only the store's tests/
|
|
|
126301
126855
|
if (opts.json)
|
|
126302
126856
|
console.log(JSON.stringify({ url: opts.url, issues }));
|
|
126303
126857
|
else if (!issues.length)
|
|
126304
|
-
console.log(
|
|
126858
|
+
console.log(chalk50.green(" regression suite: all passed"));
|
|
126305
126859
|
else
|
|
126306
126860
|
for (const i of issues)
|
|
126307
|
-
console.log((i.inconclusive ?
|
|
126861
|
+
console.log((i.inconclusive ? chalk50.yellow : chalk50.red)(` ${i.summary}`));
|
|
126308
126862
|
process.exit(regressed ? 1 : unverified ? 2 : 0);
|
|
126309
126863
|
}));
|
|
126310
126864
|
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) => {
|
|
@@ -126658,6 +127212,9 @@ program.command("drift").description("How far has the SOURCE repo moved since th
|
|
|
126658
127212
|
json: opts.json
|
|
126659
127213
|
}));
|
|
126660
127214
|
});
|
|
127215
|
+
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
|
+
process.exit(capacityCommand(opts));
|
|
127217
|
+
});
|
|
126661
127218
|
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) => {
|
|
126662
127219
|
process.exit(varianceCommand({
|
|
126663
127220
|
runIds,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.35",
|
|
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",
|