@decocms/parity 0.33.32 → 0.33.33
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/dist/cli.js +2910 -548
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -39004,6 +39004,63 @@ async function waitForSkeletonsToResolve(page, maxMs = 1e4) {
|
|
|
39004
39004
|
});
|
|
39005
39005
|
}
|
|
39006
39006
|
}
|
|
39007
|
+
var SETTLE_SAMPLES = 3;
|
|
39008
|
+
var SETTLE_INTERVAL_MS = 200;
|
|
39009
|
+
async function waitForLayoutStable(page, maxMs = 8000) {
|
|
39010
|
+
const start = Date.now();
|
|
39011
|
+
const sample = () => page.evaluate(() => ({
|
|
39012
|
+
height: document.body?.scrollHeight ?? 0,
|
|
39013
|
+
elements: document.querySelectorAll("*").length
|
|
39014
|
+
})).catch(() => null);
|
|
39015
|
+
let last = null;
|
|
39016
|
+
let repeats = 0;
|
|
39017
|
+
let samples = 0;
|
|
39018
|
+
while (Date.now() - start < maxMs) {
|
|
39019
|
+
const now = await sample();
|
|
39020
|
+
samples++;
|
|
39021
|
+
if (!now)
|
|
39022
|
+
break;
|
|
39023
|
+
repeats = last && now.height === last.height && now.elements === last.elements ? repeats + 1 : 0;
|
|
39024
|
+
last = now;
|
|
39025
|
+
if (repeats + 1 >= SETTLE_SAMPLES) {
|
|
39026
|
+
return { stable: true, heightPx: now.height, waitedMs: Date.now() - start, samples };
|
|
39027
|
+
}
|
|
39028
|
+
await page.waitForTimeout(SETTLE_INTERVAL_MS).catch(() => {
|
|
39029
|
+
return;
|
|
39030
|
+
});
|
|
39031
|
+
}
|
|
39032
|
+
return {
|
|
39033
|
+
stable: false,
|
|
39034
|
+
heightPx: last?.height ?? 0,
|
|
39035
|
+
waitedMs: Date.now() - start,
|
|
39036
|
+
samples
|
|
39037
|
+
};
|
|
39038
|
+
}
|
|
39039
|
+
async function reloadIfOptionalFonts(page, waitMs = 0) {
|
|
39040
|
+
const optional = await page.evaluate(() => {
|
|
39041
|
+
for (const face of document.fonts) {
|
|
39042
|
+
if (face.display === "optional")
|
|
39043
|
+
return true;
|
|
39044
|
+
}
|
|
39045
|
+
return false;
|
|
39046
|
+
}).catch(() => false);
|
|
39047
|
+
if (!optional)
|
|
39048
|
+
return false;
|
|
39049
|
+
await page.reload({ waitUntil: "domcontentloaded", timeout: 30000 }).catch(() => {
|
|
39050
|
+
return;
|
|
39051
|
+
});
|
|
39052
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
39053
|
+
return;
|
|
39054
|
+
});
|
|
39055
|
+
if (waitMs > 0)
|
|
39056
|
+
await page.waitForTimeout(waitMs).catch(() => {
|
|
39057
|
+
return;
|
|
39058
|
+
});
|
|
39059
|
+
return true;
|
|
39060
|
+
}
|
|
39061
|
+
function formatSettleCaveat(side, settle) {
|
|
39062
|
+
return settle.stable ? null : `${side}: layout still changing after ${settle.waitedMs}ms (height ${settle.heightPx}px) — measured anyway, so a large rect delta may be a timing artifact`;
|
|
39063
|
+
}
|
|
39007
39064
|
async function scrollFullPage(page, budgetMs = 45000) {
|
|
39008
39065
|
const start = Date.now();
|
|
39009
39066
|
const result = await page.evaluate(async (budget) => {
|
|
@@ -41558,6 +41615,13 @@ var RunCaveat = z.object({
|
|
|
41558
41615
|
summary: z.string(),
|
|
41559
41616
|
detail: z.string()
|
|
41560
41617
|
});
|
|
41618
|
+
var ScoreBand = z.object({
|
|
41619
|
+
scores: z.array(z.number()),
|
|
41620
|
+
spread: z.number(),
|
|
41621
|
+
priorRuns: z.number(),
|
|
41622
|
+
flipping: z.array(z.object({ name: z.string(), statuses: z.array(z.string()) })),
|
|
41623
|
+
worthShowing: z.boolean()
|
|
41624
|
+
});
|
|
41561
41625
|
var Run = z.object({
|
|
41562
41626
|
schemaVersion: z.literal("0.1"),
|
|
41563
41627
|
id: z.string(),
|
|
@@ -41569,6 +41633,7 @@ var Run = z.object({
|
|
|
41569
41633
|
cep: z.string(),
|
|
41570
41634
|
durationMs: z.number(),
|
|
41571
41635
|
verdict: Verdict,
|
|
41636
|
+
scoreBand: ScoreBand.optional(),
|
|
41572
41637
|
previousRun: z.object({
|
|
41573
41638
|
id: z.string(),
|
|
41574
41639
|
timestamp: z.string(),
|
|
@@ -41761,6 +41826,9 @@ function sameModuleSet(a, b) {
|
|
|
41761
41826
|
return true;
|
|
41762
41827
|
}
|
|
41763
41828
|
function findPreviousRun(outputDir, opts) {
|
|
41829
|
+
return findComparableRuns(outputDir, opts, 1)[0] ?? null;
|
|
41830
|
+
}
|
|
41831
|
+
function findComparableRuns(outputDir, opts, limit) {
|
|
41764
41832
|
const hostOf = (url) => {
|
|
41765
41833
|
try {
|
|
41766
41834
|
return new URL(url).hostname;
|
|
@@ -41770,7 +41838,10 @@ function findPreviousRun(outputDir, opts) {
|
|
|
41770
41838
|
};
|
|
41771
41839
|
const prodHost = hostOf(opts.prodUrl);
|
|
41772
41840
|
const candHost = hostOf(opts.candUrl);
|
|
41841
|
+
const out = [];
|
|
41773
41842
|
for (const entry of listRuns(outputDir)) {
|
|
41843
|
+
if (out.length >= limit)
|
|
41844
|
+
break;
|
|
41774
41845
|
if (entry.id === opts.excludeRunId)
|
|
41775
41846
|
continue;
|
|
41776
41847
|
try {
|
|
@@ -41788,14 +41859,15 @@ function findPreviousRun(outputDir, opts) {
|
|
|
41788
41859
|
if (!sameModuleSet(candidateModules, opts.modulesRun))
|
|
41789
41860
|
continue;
|
|
41790
41861
|
}
|
|
41791
|
-
|
|
41862
|
+
out.push({
|
|
41792
41863
|
id: raw.id ?? entry.id,
|
|
41793
41864
|
timestamp: raw.timestamp ?? entry.timestamp,
|
|
41794
|
-
score: raw.verdict.score
|
|
41795
|
-
|
|
41865
|
+
score: raw.verdict.score,
|
|
41866
|
+
reportPath: entry.reportPath
|
|
41867
|
+
});
|
|
41796
41868
|
} catch {}
|
|
41797
41869
|
}
|
|
41798
|
-
return
|
|
41870
|
+
return out;
|
|
41799
41871
|
}
|
|
41800
41872
|
function listRuns(outputDir) {
|
|
41801
41873
|
const runsDir = join(outputDir, "runs");
|
|
@@ -62302,12 +62374,13 @@ function sanitizeDetectedComponents(components) {
|
|
|
62302
62374
|
}
|
|
62303
62375
|
return out;
|
|
62304
62376
|
}
|
|
62377
|
+
var ZERO_AREA_ALLOWED = new Set(["header", "footer", "nav", "banner"]);
|
|
62305
62378
|
function dedupeByContainment(candidates) {
|
|
62306
|
-
const valid = candidates.filter((c) => c.rect.width > 0 && c.rect.height > 0);
|
|
62379
|
+
const valid = candidates.filter((c) => c.rect.width > 0 && c.rect.height > 0 || ZERO_AREA_ALLOWED.has(c.role));
|
|
62307
62380
|
const sorted = [...valid].sort((a, b) => boxArea(b.rect) - boxArea(a.rect));
|
|
62308
62381
|
const accepted = [];
|
|
62309
62382
|
for (const candidate of sorted) {
|
|
62310
|
-
const containedInAccepted = accepted.some((a) => a.priority >= candidate.priority && containmentRatio(candidate.rect, a.rect) >= 0.9);
|
|
62383
|
+
const containedInAccepted = boxArea(candidate.rect) > 0 && accepted.some((a) => boxArea(a.rect) > 0 && a.priority >= candidate.priority && containmentRatio(candidate.rect, a.rect) >= 0.9);
|
|
62311
62384
|
if (containedInAccepted)
|
|
62312
62385
|
continue;
|
|
62313
62386
|
accepted.push(candidate);
|
|
@@ -63637,6 +63710,483 @@ function capDiff(diff, maxLines) {
|
|
|
63637
63710
|
`);
|
|
63638
63711
|
}
|
|
63639
63712
|
|
|
63713
|
+
// src/migrate/plan.ts
|
|
63714
|
+
import { existsSync as existsSync16, readFileSync as readFileSync21, writeFileSync as writeFileSync21 } from "node:fs";
|
|
63715
|
+
import { join as join25 } from "node:path";
|
|
63716
|
+
function dedupe(names) {
|
|
63717
|
+
return [...new Set(names)];
|
|
63718
|
+
}
|
|
63719
|
+
function key(name) {
|
|
63720
|
+
return name.toLowerCase().replace(/[\s_/-]+/g, "");
|
|
63721
|
+
}
|
|
63722
|
+
function buildMigrationPlan(input) {
|
|
63723
|
+
const { bundle, source, inventory } = input;
|
|
63724
|
+
const liveByKey = new Map;
|
|
63725
|
+
for (const c of bundle.components) {
|
|
63726
|
+
liveByKey.set(key(c.role), { role: c.role, scope: c.scope, selector: c.selector });
|
|
63727
|
+
}
|
|
63728
|
+
const srcByKey = new Map;
|
|
63729
|
+
for (const c of inventory.components)
|
|
63730
|
+
srcByKey.set(key(c.name), c);
|
|
63731
|
+
const components = [];
|
|
63732
|
+
for (const [k, c] of srcByKey) {
|
|
63733
|
+
components.push({
|
|
63734
|
+
name: c.name,
|
|
63735
|
+
role: c.role,
|
|
63736
|
+
scope: c.scope,
|
|
63737
|
+
origin: liveByKey.has(k) ? "both" : "source-only",
|
|
63738
|
+
status: "pending",
|
|
63739
|
+
file: c.file,
|
|
63740
|
+
selector: liveByKey.get(k)?.selector ?? null,
|
|
63741
|
+
reference: null,
|
|
63742
|
+
verified: null
|
|
63743
|
+
});
|
|
63744
|
+
}
|
|
63745
|
+
for (const [k, c] of liveByKey) {
|
|
63746
|
+
if (srcByKey.has(k))
|
|
63747
|
+
continue;
|
|
63748
|
+
components.push({
|
|
63749
|
+
name: c.role,
|
|
63750
|
+
role: c.role,
|
|
63751
|
+
scope: c.scope,
|
|
63752
|
+
origin: "live-only",
|
|
63753
|
+
status: "pending",
|
|
63754
|
+
file: null,
|
|
63755
|
+
selector: c.selector,
|
|
63756
|
+
reference: null,
|
|
63757
|
+
verified: null
|
|
63758
|
+
});
|
|
63759
|
+
}
|
|
63760
|
+
return {
|
|
63761
|
+
url: bundle.url,
|
|
63762
|
+
timestamp: bundle.timestamp,
|
|
63763
|
+
source: {
|
|
63764
|
+
kind: source.kind,
|
|
63765
|
+
label: source.label,
|
|
63766
|
+
dir: source.dir,
|
|
63767
|
+
notes: inventory.notes,
|
|
63768
|
+
...input.searched ? { searched: input.searched } : {},
|
|
63769
|
+
...input.project ? { project: input.project } : {}
|
|
63770
|
+
},
|
|
63771
|
+
target: { name: bundle.target ?? null },
|
|
63772
|
+
pages: bundle.pages.map((p) => ({
|
|
63773
|
+
path: p.path,
|
|
63774
|
+
kind: p.kind,
|
|
63775
|
+
status: "pending",
|
|
63776
|
+
components: dedupe((p.components ?? []).map((c) => components.find((row) => key(row.name) === key(c.role))?.name ?? c.role))
|
|
63777
|
+
})),
|
|
63778
|
+
components
|
|
63779
|
+
};
|
|
63780
|
+
}
|
|
63781
|
+
function mergePlanDecisions(fresh, previous) {
|
|
63782
|
+
if (!previous)
|
|
63783
|
+
return { plan: fresh, carried: [], keptUncaptured: [], droppedWithDecisions: [] };
|
|
63784
|
+
const prevByKey = new Map(previous.components.map((c) => [key(c.name), c]));
|
|
63785
|
+
const carried = [];
|
|
63786
|
+
for (const row of fresh.components) {
|
|
63787
|
+
const prev = prevByKey.get(key(row.name));
|
|
63788
|
+
if (!prev)
|
|
63789
|
+
continue;
|
|
63790
|
+
if (prev.status !== "pending")
|
|
63791
|
+
row.status = prev.status;
|
|
63792
|
+
if (prev.reference)
|
|
63793
|
+
row.reference = prev.reference;
|
|
63794
|
+
if (prev.verified)
|
|
63795
|
+
row.verified = prev.verified;
|
|
63796
|
+
if (prev.provenance)
|
|
63797
|
+
row.provenance = prev.provenance;
|
|
63798
|
+
if (prev.status !== "pending" || prev.reference || prev.verified)
|
|
63799
|
+
carried.push(row.name);
|
|
63800
|
+
}
|
|
63801
|
+
const freshKeys = new Set(fresh.components.map((c) => key(c.name)));
|
|
63802
|
+
const keptUncaptured = [];
|
|
63803
|
+
for (const prev of previous.components) {
|
|
63804
|
+
if (freshKeys.has(key(prev.name)))
|
|
63805
|
+
continue;
|
|
63806
|
+
const hasDecision = prev.status !== "pending" || Boolean(prev.reference) || Boolean(prev.verified);
|
|
63807
|
+
if (prev.origin !== "manual" && !hasDecision)
|
|
63808
|
+
continue;
|
|
63809
|
+
fresh.components.push(prev);
|
|
63810
|
+
keptUncaptured.push(prev.name);
|
|
63811
|
+
}
|
|
63812
|
+
const prevPages = new Map(previous.pages.map((p) => [p.path, p]));
|
|
63813
|
+
for (const page of fresh.pages) {
|
|
63814
|
+
const prev = prevPages.get(page.path);
|
|
63815
|
+
if (prev?.status && prev.status !== "pending")
|
|
63816
|
+
page.status = prev.status;
|
|
63817
|
+
if (prev?.boardItemId)
|
|
63818
|
+
page.boardItemId = prev.boardItemId;
|
|
63819
|
+
}
|
|
63820
|
+
const freshPaths = new Set(fresh.pages.map((p) => p.path));
|
|
63821
|
+
for (const prev of previous.pages) {
|
|
63822
|
+
if (freshPaths.has(prev.path))
|
|
63823
|
+
continue;
|
|
63824
|
+
if (prev.status === "pending")
|
|
63825
|
+
continue;
|
|
63826
|
+
fresh.pages.push(prev);
|
|
63827
|
+
keptUncaptured.push(prev.path);
|
|
63828
|
+
}
|
|
63829
|
+
if (previous.telemetry)
|
|
63830
|
+
fresh.telemetry = previous.telemetry;
|
|
63831
|
+
return { plan: fresh, carried, keptUncaptured, droppedWithDecisions: [] };
|
|
63832
|
+
}
|
|
63833
|
+
var PLAN_FILE = "migration-plan.json";
|
|
63834
|
+
var SETTLED = new Set(["done", "as-is", "upgrade", "skipped"]);
|
|
63835
|
+
function loadPlan(dir) {
|
|
63836
|
+
const p = join25(dir, PLAN_FILE);
|
|
63837
|
+
if (!existsSync16(p))
|
|
63838
|
+
return null;
|
|
63839
|
+
return JSON.parse(readFileSync21(p, "utf8"));
|
|
63840
|
+
}
|
|
63841
|
+
function savePlan(dir, plan) {
|
|
63842
|
+
writeFileSync21(join25(dir, PLAN_FILE), `${JSON.stringify(plan, null, 2)}
|
|
63843
|
+
`, "utf8");
|
|
63844
|
+
}
|
|
63845
|
+
function setComponentStatus(plan, name, status, opts = {}) {
|
|
63846
|
+
const k = key(name);
|
|
63847
|
+
const component = plan.components.find((c) => key(c.name) === k);
|
|
63848
|
+
if (component) {
|
|
63849
|
+
component.status = status;
|
|
63850
|
+
return component;
|
|
63851
|
+
}
|
|
63852
|
+
if (!opts.create)
|
|
63853
|
+
return null;
|
|
63854
|
+
const created = {
|
|
63855
|
+
name,
|
|
63856
|
+
role: opts.create.role ?? name,
|
|
63857
|
+
scope: opts.create.scope,
|
|
63858
|
+
origin: "manual",
|
|
63859
|
+
status,
|
|
63860
|
+
file: null,
|
|
63861
|
+
selector: null,
|
|
63862
|
+
reference: null,
|
|
63863
|
+
verified: null
|
|
63864
|
+
};
|
|
63865
|
+
plan.components.push(created);
|
|
63866
|
+
return created;
|
|
63867
|
+
}
|
|
63868
|
+
function setComponentProvenance(plan, name, provenance) {
|
|
63869
|
+
const k = key(name);
|
|
63870
|
+
const component = plan.components.find((c) => key(c.name) === k);
|
|
63871
|
+
if (!component)
|
|
63872
|
+
return null;
|
|
63873
|
+
component.provenance = provenance;
|
|
63874
|
+
return component;
|
|
63875
|
+
}
|
|
63876
|
+
function recordTouch(plan, path) {
|
|
63877
|
+
const page = findPage(plan, path);
|
|
63878
|
+
const kk = page?.path ?? path;
|
|
63879
|
+
plan.telemetry ??= {};
|
|
63880
|
+
plan.telemetry.touches ??= {};
|
|
63881
|
+
const next = (plan.telemetry.touches[kk] ?? 0) + 1;
|
|
63882
|
+
plan.telemetry.touches[kk] = next;
|
|
63883
|
+
return next;
|
|
63884
|
+
}
|
|
63885
|
+
function totalTouches(plan) {
|
|
63886
|
+
return Object.values(plan.telemetry?.touches ?? {}).reduce((a, b) => a + b, 0);
|
|
63887
|
+
}
|
|
63888
|
+
function provenanceCounts(plan) {
|
|
63889
|
+
let library = 0;
|
|
63890
|
+
let built = 0;
|
|
63891
|
+
let unrecorded = 0;
|
|
63892
|
+
for (const c of plan.components) {
|
|
63893
|
+
if (c.provenance === "library")
|
|
63894
|
+
library++;
|
|
63895
|
+
else if (c.provenance === "built")
|
|
63896
|
+
built++;
|
|
63897
|
+
else
|
|
63898
|
+
unrecorded++;
|
|
63899
|
+
}
|
|
63900
|
+
return { library, built, unrecorded };
|
|
63901
|
+
}
|
|
63902
|
+
function setPageStatus(plan, path, status) {
|
|
63903
|
+
const page = findPage(plan, path);
|
|
63904
|
+
if (!page)
|
|
63905
|
+
return null;
|
|
63906
|
+
page.status = status;
|
|
63907
|
+
return page;
|
|
63908
|
+
}
|
|
63909
|
+
function findPage(plan, path) {
|
|
63910
|
+
const norm = (p) => `/${p.trim().replace(/^\/+|\/+$/g, "")}` || "/";
|
|
63911
|
+
const target = norm(path);
|
|
63912
|
+
return plan.pages.find((p) => p.path === path) ?? plan.pages.find((p) => norm(p.path) === target) ?? null;
|
|
63913
|
+
}
|
|
63914
|
+
function setPageBoardItemId(plan, path, boardItemId) {
|
|
63915
|
+
const page = findPage(plan, path);
|
|
63916
|
+
if (!page)
|
|
63917
|
+
return null;
|
|
63918
|
+
page.boardItemId = boardItemId;
|
|
63919
|
+
return page;
|
|
63920
|
+
}
|
|
63921
|
+
function planProgress(plan) {
|
|
63922
|
+
const compByStatus = {
|
|
63923
|
+
pending: 0,
|
|
63924
|
+
partial: 0,
|
|
63925
|
+
done: 0,
|
|
63926
|
+
"as-is": 0,
|
|
63927
|
+
upgrade: 0,
|
|
63928
|
+
skipped: 0
|
|
63929
|
+
};
|
|
63930
|
+
const settled = [];
|
|
63931
|
+
const settledByStatus = { done: [], skipped: [] };
|
|
63932
|
+
const accepted = { asIs: [], upgrade: [] };
|
|
63933
|
+
const remaining = [];
|
|
63934
|
+
for (const c of plan.components) {
|
|
63935
|
+
compByStatus[c.status] = (compByStatus[c.status] ?? 0) + 1;
|
|
63936
|
+
if (c.status === "as-is")
|
|
63937
|
+
accepted.asIs.push(c.name);
|
|
63938
|
+
if (c.status === "upgrade")
|
|
63939
|
+
accepted.upgrade.push(c.name);
|
|
63940
|
+
if (c.status === "done")
|
|
63941
|
+
settledByStatus.done.push(c.name);
|
|
63942
|
+
if (c.status === "skipped")
|
|
63943
|
+
settledByStatus.skipped.push(c.name);
|
|
63944
|
+
if (SETTLED.has(c.status))
|
|
63945
|
+
settled.push(c.name);
|
|
63946
|
+
else
|
|
63947
|
+
remaining.push({
|
|
63948
|
+
name: c.name,
|
|
63949
|
+
status: c.status,
|
|
63950
|
+
scope: c.scope ?? "page",
|
|
63951
|
+
origin: c.origin
|
|
63952
|
+
});
|
|
63953
|
+
}
|
|
63954
|
+
const pageByStatus = { pending: 0, code: 0, done: 0, skipped: 0 };
|
|
63955
|
+
const awaitingContent = [];
|
|
63956
|
+
const pagesRemaining = [];
|
|
63957
|
+
for (const p of plan.pages) {
|
|
63958
|
+
const status = p.status ?? "pending";
|
|
63959
|
+
pageByStatus[status] = (pageByStatus[status] ?? 0) + 1;
|
|
63960
|
+
if (status === "code")
|
|
63961
|
+
awaitingContent.push(p.path);
|
|
63962
|
+
if (status !== "done" && status !== "skipped") {
|
|
63963
|
+
pagesRemaining.push({ path: p.path, kind: p.kind, status });
|
|
63964
|
+
}
|
|
63965
|
+
}
|
|
63966
|
+
return {
|
|
63967
|
+
components: {
|
|
63968
|
+
total: plan.components.length,
|
|
63969
|
+
byStatus: compByStatus,
|
|
63970
|
+
settled,
|
|
63971
|
+
settledByStatus,
|
|
63972
|
+
accepted,
|
|
63973
|
+
remaining
|
|
63974
|
+
},
|
|
63975
|
+
pages: {
|
|
63976
|
+
total: plan.pages.length,
|
|
63977
|
+
byStatus: pageByStatus,
|
|
63978
|
+
awaitingContent,
|
|
63979
|
+
remaining: pagesRemaining
|
|
63980
|
+
}
|
|
63981
|
+
};
|
|
63982
|
+
}
|
|
63983
|
+
function joinUrl(base, path) {
|
|
63984
|
+
return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`.replace(/\/$/, "") || base;
|
|
63985
|
+
}
|
|
63986
|
+
function shellQuote(value) {
|
|
63987
|
+
return /^[\w./:=-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
63988
|
+
}
|
|
63989
|
+
function disposition(c) {
|
|
63990
|
+
if (c.status === "pending" || c.status === "partial")
|
|
63991
|
+
return "build";
|
|
63992
|
+
if (c.status === "skipped")
|
|
63993
|
+
return "settled";
|
|
63994
|
+
if (c.status === "as-is")
|
|
63995
|
+
return "as-is";
|
|
63996
|
+
if (c.verified)
|
|
63997
|
+
return "settled";
|
|
63998
|
+
if (c.status === "upgrade")
|
|
63999
|
+
return c.reference ? "validate" : "upgrade";
|
|
64000
|
+
return "validate";
|
|
64001
|
+
}
|
|
64002
|
+
function pagePlan(plan, path, candUrl) {
|
|
64003
|
+
const page = findPage(plan, path);
|
|
64004
|
+
if (!page)
|
|
64005
|
+
return null;
|
|
64006
|
+
const counts = {
|
|
64007
|
+
build: 0,
|
|
64008
|
+
validate: 0,
|
|
64009
|
+
upgrade: 0,
|
|
64010
|
+
"as-is": 0,
|
|
64011
|
+
settled: 0
|
|
64012
|
+
};
|
|
64013
|
+
let tasks = null;
|
|
64014
|
+
if (page.components) {
|
|
64015
|
+
tasks = [];
|
|
64016
|
+
for (const name of page.components) {
|
|
64017
|
+
const c = plan.components.find((row) => key(row.name) === key(name));
|
|
64018
|
+
if (!c)
|
|
64019
|
+
continue;
|
|
64020
|
+
const d = disposition(c);
|
|
64021
|
+
counts[d] += 1;
|
|
64022
|
+
const selector = c.reference?.selector ?? c.selector ?? null;
|
|
64023
|
+
const refUrl = c.reference?.url ?? plan.url;
|
|
64024
|
+
const kind = c.reference ? "reference" : "prod";
|
|
64025
|
+
const checkable = d === "validate" && Boolean(selector) && Boolean(candUrl);
|
|
64026
|
+
tasks.push({
|
|
64027
|
+
name: c.name,
|
|
64028
|
+
disposition: d,
|
|
64029
|
+
status: c.status,
|
|
64030
|
+
scope: c.scope ?? "page",
|
|
64031
|
+
origin: c.origin,
|
|
64032
|
+
selector,
|
|
64033
|
+
against: d === "validate" ? { url: refUrl, kind } : null,
|
|
64034
|
+
command: checkable && candUrl && selector ? `parity section --prod ${shellQuote(joinUrl(refUrl, page.path))} --cand ${shellQuote(joinUrl(candUrl, page.path))} --selector ${shellQuote(selector)}` : null,
|
|
64035
|
+
note: c.reference?.note ?? null
|
|
64036
|
+
});
|
|
64037
|
+
}
|
|
64038
|
+
}
|
|
64039
|
+
return {
|
|
64040
|
+
path: page.path,
|
|
64041
|
+
kind: page.kind,
|
|
64042
|
+
status: page.status ?? "pending",
|
|
64043
|
+
tasks,
|
|
64044
|
+
counts,
|
|
64045
|
+
ready: counts.build === 0 && counts.validate === 0
|
|
64046
|
+
};
|
|
64047
|
+
}
|
|
64048
|
+
function pageColumn(page) {
|
|
64049
|
+
if (page.status === "skipped")
|
|
64050
|
+
return "skipped";
|
|
64051
|
+
if (page.status === "done")
|
|
64052
|
+
return "done";
|
|
64053
|
+
if (page.tasks === null || page.tasks.length === 0)
|
|
64054
|
+
return "triage";
|
|
64055
|
+
if (page.ready)
|
|
64056
|
+
return "review";
|
|
64057
|
+
const started = page.counts.settled + page.counts.validate + page.counts["as-is"] + page.counts.upgrade;
|
|
64058
|
+
return started > 0 ? "building" : "backlog";
|
|
64059
|
+
}
|
|
64060
|
+
function planBoard(plan, candUrl) {
|
|
64061
|
+
const columns = {
|
|
64062
|
+
triage: [],
|
|
64063
|
+
backlog: [],
|
|
64064
|
+
building: [],
|
|
64065
|
+
review: [],
|
|
64066
|
+
done: [],
|
|
64067
|
+
skipped: []
|
|
64068
|
+
};
|
|
64069
|
+
for (const p of plan.pages) {
|
|
64070
|
+
const page = pagePlan(plan, p.path, candUrl);
|
|
64071
|
+
if (!page)
|
|
64072
|
+
continue;
|
|
64073
|
+
const column = pageColumn(page);
|
|
64074
|
+
columns[column].push({
|
|
64075
|
+
path: page.path,
|
|
64076
|
+
kind: page.kind,
|
|
64077
|
+
column,
|
|
64078
|
+
blockers: (page.tasks ?? []).filter((t) => t.disposition === "build" && t.scope !== "global").map((t) => t.name),
|
|
64079
|
+
counts: page.counts,
|
|
64080
|
+
ready: page.ready,
|
|
64081
|
+
boardItemId: p.boardItemId
|
|
64082
|
+
});
|
|
64083
|
+
}
|
|
64084
|
+
const onAnyPage = new Set(plan.pages.flatMap((p) => (p.components ?? []).map(key)));
|
|
64085
|
+
const shell = [];
|
|
64086
|
+
const unassigned = [];
|
|
64087
|
+
for (const c of plan.components) {
|
|
64088
|
+
if (c.scope === "global") {
|
|
64089
|
+
if (disposition(c) === "build")
|
|
64090
|
+
shell.push(c.name);
|
|
64091
|
+
} else if (!onAnyPage.has(key(c.name))) {
|
|
64092
|
+
unassigned.push(c.name);
|
|
64093
|
+
}
|
|
64094
|
+
}
|
|
64095
|
+
return { url: plan.url, columns, shell, unassigned, sampled: plan.pages.length };
|
|
64096
|
+
}
|
|
64097
|
+
function setComponentVerified(plan, name, verdict, at, note) {
|
|
64098
|
+
const k = key(name);
|
|
64099
|
+
const component = plan.components.find((c) => key(c.name) === k);
|
|
64100
|
+
if (!component)
|
|
64101
|
+
return null;
|
|
64102
|
+
const against = component.reference ? "reference" : "prod";
|
|
64103
|
+
component.verified = { at, verdict, against, ...note ? { note } : {} };
|
|
64104
|
+
return component;
|
|
64105
|
+
}
|
|
64106
|
+
function setComponentReference(plan, name, reference) {
|
|
64107
|
+
const k = key(name);
|
|
64108
|
+
const component = plan.components.find((c) => key(c.name) === k);
|
|
64109
|
+
if (!component)
|
|
64110
|
+
return null;
|
|
64111
|
+
component.reference = reference;
|
|
64112
|
+
return component;
|
|
64113
|
+
}
|
|
64114
|
+
function syntheticSourceComponents(plan) {
|
|
64115
|
+
return plan.components.filter((c) => c.origin === "source-only").map((c) => ({
|
|
64116
|
+
role: c.name,
|
|
64117
|
+
selector: "",
|
|
64118
|
+
html: "",
|
|
64119
|
+
computedStyles: null,
|
|
64120
|
+
screenshotPath: "",
|
|
64121
|
+
assets: { images: [], backgroundImages: [], fonts: [] },
|
|
64122
|
+
links: [],
|
|
64123
|
+
textContent: [],
|
|
64124
|
+
tailwind: [],
|
|
64125
|
+
interactions: [],
|
|
64126
|
+
scope: c.scope ?? "page",
|
|
64127
|
+
synthetic: true
|
|
64128
|
+
}));
|
|
64129
|
+
}
|
|
64130
|
+
|
|
64131
|
+
// src/migrate/aliases.ts
|
|
64132
|
+
var DIR_NOISE = new Set(["site", "src", "app", "components", "sections", "islands", "blocks"]);
|
|
64133
|
+
function fileSpellings(file) {
|
|
64134
|
+
const clean = file.replace(/^\.?\//, "");
|
|
64135
|
+
const segs = clean.split("/").filter(Boolean);
|
|
64136
|
+
const meaningful = segs.filter((s, i) => i === segs.length - 1 || !DIR_NOISE.has(s));
|
|
64137
|
+
const base = segs[segs.length - 1] ?? "";
|
|
64138
|
+
const stem = base.replace(/\.[jt]sx?$/, "");
|
|
64139
|
+
const out = [clean, meaningful.join("/"), base, stem];
|
|
64140
|
+
if (meaningful.length > 1)
|
|
64141
|
+
out.push(meaningful.slice(-2).join("/"));
|
|
64142
|
+
return out.filter(Boolean);
|
|
64143
|
+
}
|
|
64144
|
+
function buildLabelAliases(plan) {
|
|
64145
|
+
const claims = new Map;
|
|
64146
|
+
const claim = (spelling, canonical) => {
|
|
64147
|
+
if (!spelling || spelling === canonical)
|
|
64148
|
+
return;
|
|
64149
|
+
const set = claims.get(spelling) ?? new Set;
|
|
64150
|
+
set.add(canonical);
|
|
64151
|
+
claims.set(spelling, set);
|
|
64152
|
+
};
|
|
64153
|
+
for (const c of plan.components) {
|
|
64154
|
+
if (!c.name)
|
|
64155
|
+
continue;
|
|
64156
|
+
if (c.file)
|
|
64157
|
+
for (const s of fileSpellings(c.file))
|
|
64158
|
+
claim(s, c.name);
|
|
64159
|
+
if (c.selector)
|
|
64160
|
+
claim(c.selector.replace(/^\[data-[a-z-]+=["']?|["']?\]$/g, ""), c.name);
|
|
64161
|
+
}
|
|
64162
|
+
const out = new Map;
|
|
64163
|
+
for (const [spelling, canonicals] of claims) {
|
|
64164
|
+
const only = canonicals.size === 1 ? [...canonicals][0] : undefined;
|
|
64165
|
+
if (only)
|
|
64166
|
+
out.set(spelling, only);
|
|
64167
|
+
}
|
|
64168
|
+
return out;
|
|
64169
|
+
}
|
|
64170
|
+
function canonicalLabel(aliases, label) {
|
|
64171
|
+
return aliases?.get(label) ?? label;
|
|
64172
|
+
}
|
|
64173
|
+
function loadLabelAliases(dir) {
|
|
64174
|
+
const plan = loadPlan(dir);
|
|
64175
|
+
return { aliases: plan ? buildLabelAliases(plan) : new Map, plan };
|
|
64176
|
+
}
|
|
64177
|
+
function resolveAliases(planDir) {
|
|
64178
|
+
if (!planDir)
|
|
64179
|
+
return { aliases: new Map, note: null };
|
|
64180
|
+
const { aliases, plan } = loadLabelAliases(planDir);
|
|
64181
|
+
if (!plan) {
|
|
64182
|
+
return { aliases, note: `no migration-plan.json in ${planDir} — label pairing unchanged` };
|
|
64183
|
+
}
|
|
64184
|
+
return {
|
|
64185
|
+
aliases,
|
|
64186
|
+
note: `plan aliases: ${aliases.size} spelling${aliases.size === 1 ? "" : "s"} from ${plan.components.length} component rows`
|
|
64187
|
+
};
|
|
64188
|
+
}
|
|
64189
|
+
|
|
63640
64190
|
// src/diff/box-tree.ts
|
|
63641
64191
|
var STRUCTURAL_PROPS = new Set([
|
|
63642
64192
|
"display",
|
|
@@ -63654,8 +64204,24 @@ var STRUCTURAL_PROPS = new Set([
|
|
|
63654
64204
|
"grid-template-columns",
|
|
63655
64205
|
"grid-template-rows"
|
|
63656
64206
|
]);
|
|
64207
|
+
var TYPE_PROPS = new Set([
|
|
64208
|
+
"font-size",
|
|
64209
|
+
"font-weight",
|
|
64210
|
+
"line-height",
|
|
64211
|
+
"letter-spacing",
|
|
64212
|
+
"text-transform",
|
|
64213
|
+
"text-align"
|
|
64214
|
+
]);
|
|
64215
|
+
var TYPE_CHANGE_WEIGHT = 2000;
|
|
64216
|
+
var STRUCTURAL_CHANGE_WEIGHT = 1000;
|
|
63657
64217
|
var VALUE_CHANGE_WEIGHT = 8;
|
|
63658
|
-
var
|
|
64218
|
+
var PX_WEIGHT_CEILING = 999;
|
|
64219
|
+
function pxWeight(deltaPx) {
|
|
64220
|
+
return Math.min(Math.abs(deltaPx), PX_WEIGHT_CEILING);
|
|
64221
|
+
}
|
|
64222
|
+
function isTypeChange(prop, node) {
|
|
64223
|
+
return TYPE_PROPS.has(prop) && Boolean(node.text);
|
|
64224
|
+
}
|
|
63659
64225
|
function parsePx(value) {
|
|
63660
64226
|
const v = value.trim();
|
|
63661
64227
|
if (!v)
|
|
@@ -63673,49 +64239,215 @@ function indexByKey(nodes) {
|
|
|
63673
64239
|
out.set(n.key, n);
|
|
63674
64240
|
return out;
|
|
63675
64241
|
}
|
|
63676
|
-
function
|
|
63677
|
-
const
|
|
64242
|
+
function parentKey(key) {
|
|
64243
|
+
const i = key.lastIndexOf(">");
|
|
64244
|
+
return i < 0 ? null : key.slice(0, i);
|
|
64245
|
+
}
|
|
64246
|
+
var isHidden = (n) => n.styles.display === "none" || n.rect.width * n.rect.height === 0;
|
|
64247
|
+
var substantial = (n) => n.rect.width >= 8 && n.rect.height >= 8;
|
|
64248
|
+
function isVisuallyHidden(n) {
|
|
64249
|
+
const pos = n.styles.position;
|
|
64250
|
+
if (pos !== "absolute" && pos !== "fixed")
|
|
64251
|
+
return false;
|
|
64252
|
+
return n.rect.width <= 1 || n.rect.height <= 1;
|
|
64253
|
+
}
|
|
64254
|
+
function sameKindOfBox(p, c) {
|
|
64255
|
+
if (isHidden(p) !== isHidden(c) && (substantial(p) || substantial(c)))
|
|
64256
|
+
return false;
|
|
64257
|
+
if (Boolean(p.text) !== Boolean(c.text))
|
|
64258
|
+
return false;
|
|
64259
|
+
if (textsDisagree(p, c))
|
|
64260
|
+
return false;
|
|
64261
|
+
return true;
|
|
64262
|
+
}
|
|
64263
|
+
function contentTokens(n) {
|
|
64264
|
+
const out = new Set;
|
|
64265
|
+
for (const w of (n.text ?? "").toLowerCase().split(/[^\p{L}\p{N}]+/u)) {
|
|
64266
|
+
if (w.length >= 3)
|
|
64267
|
+
out.add(w);
|
|
64268
|
+
}
|
|
64269
|
+
return out;
|
|
64270
|
+
}
|
|
64271
|
+
function textsDisagree(p, c) {
|
|
64272
|
+
const pt = contentTokens(p);
|
|
64273
|
+
if (pt.size === 0)
|
|
64274
|
+
return false;
|
|
64275
|
+
const ct = contentTokens(c);
|
|
64276
|
+
if (ct.size === 0)
|
|
64277
|
+
return false;
|
|
64278
|
+
for (const w of pt)
|
|
64279
|
+
if (ct.has(w))
|
|
64280
|
+
return false;
|
|
64281
|
+
return true;
|
|
64282
|
+
}
|
|
64283
|
+
function textAnchor(n) {
|
|
64284
|
+
const t = n.text?.trim();
|
|
64285
|
+
return t && t.length >= 3 ? t : null;
|
|
64286
|
+
}
|
|
64287
|
+
function uniqueIndex(nodes, keyOf) {
|
|
64288
|
+
const groups = new Map;
|
|
63678
64289
|
for (const n of nodes) {
|
|
63679
|
-
|
|
64290
|
+
const k = keyOf(n);
|
|
64291
|
+
if (!k)
|
|
63680
64292
|
continue;
|
|
63681
|
-
|
|
64293
|
+
const list = groups.get(k) ?? [];
|
|
64294
|
+
list.push(n);
|
|
64295
|
+
groups.set(k, list);
|
|
63682
64296
|
}
|
|
63683
64297
|
const out = new Map;
|
|
63684
|
-
for (const [k,
|
|
63685
|
-
|
|
63686
|
-
|
|
64298
|
+
for (const [k, list] of groups) {
|
|
64299
|
+
const innermost = list.filter((n) => !list.some((o) => o !== n && o.key.startsWith(`${n.key}>`)));
|
|
64300
|
+
const only = innermost.length === 1 ? innermost[0] : undefined;
|
|
64301
|
+
if (only)
|
|
64302
|
+
out.set(k, only);
|
|
64303
|
+
}
|
|
63687
64304
|
return out;
|
|
63688
64305
|
}
|
|
63689
|
-
function
|
|
63690
|
-
const
|
|
64306
|
+
function anchorPairs(prod, cand, aliases, usedP, usedC) {
|
|
64307
|
+
const keys = [
|
|
64308
|
+
(n) => parentKey(n.key) ? null : VIRTUAL_ROOT,
|
|
64309
|
+
(n) => n.label ? canonicalLabel(aliases, n.label) : null,
|
|
64310
|
+
textAnchor
|
|
64311
|
+
];
|
|
63691
64312
|
const pairs = [];
|
|
63692
|
-
const
|
|
63693
|
-
|
|
63694
|
-
|
|
63695
|
-
const
|
|
63696
|
-
|
|
64313
|
+
for (const keyOf of keys) {
|
|
64314
|
+
const pi = uniqueIndex(prod.filter((n) => !usedP.has(n)), keyOf);
|
|
64315
|
+
const ci = uniqueIndex(cand.filter((n) => !usedC.has(n)), keyOf);
|
|
64316
|
+
for (const [k, p] of pi) {
|
|
64317
|
+
const c = ci.get(k);
|
|
64318
|
+
if (!c || usedC.has(c))
|
|
64319
|
+
continue;
|
|
63697
64320
|
pairs.push([p, c]);
|
|
63698
|
-
|
|
63699
|
-
|
|
63700
|
-
leftoverProd.push(p);
|
|
64321
|
+
usedP.add(p);
|
|
64322
|
+
usedC.add(c);
|
|
63701
64323
|
}
|
|
63702
64324
|
}
|
|
63703
|
-
|
|
63704
|
-
|
|
63705
|
-
|
|
63706
|
-
|
|
63707
|
-
|
|
63708
|
-
|
|
63709
|
-
|
|
63710
|
-
|
|
63711
|
-
|
|
63712
|
-
|
|
64325
|
+
return pairs;
|
|
64326
|
+
}
|
|
64327
|
+
var VIRTUAL_ROOT = "\x00root";
|
|
64328
|
+
function childIndex(nodes) {
|
|
64329
|
+
const present = new Set(nodes.map((n) => n.key));
|
|
64330
|
+
const out = new Map;
|
|
64331
|
+
for (const n of nodes) {
|
|
64332
|
+
const parent = parentKey(n.key);
|
|
64333
|
+
const pk = parent && present.has(parent) ? parent : VIRTUAL_ROOT;
|
|
64334
|
+
const list = out.get(pk) ?? [];
|
|
64335
|
+
list.push(n);
|
|
64336
|
+
out.set(pk, list);
|
|
64337
|
+
}
|
|
64338
|
+
return out;
|
|
64339
|
+
}
|
|
64340
|
+
function propagateAnchors(anchors, prodByKey, candByKey, usedP, usedC) {
|
|
64341
|
+
const prodKids = childIndex([...prodByKey.values()]);
|
|
64342
|
+
const candKids = childIndex([...candByKey.values()]);
|
|
64343
|
+
const claims = [];
|
|
64344
|
+
for (const [ap, ac] of anchors) {
|
|
64345
|
+
let p = ap;
|
|
64346
|
+
let c = ac;
|
|
64347
|
+
for (let dist = 1;; dist++) {
|
|
64348
|
+
const pk = parentKey(p.key);
|
|
64349
|
+
const ck = parentKey(c.key);
|
|
64350
|
+
if (!pk || !ck)
|
|
64351
|
+
break;
|
|
64352
|
+
const pp = prodByKey.get(pk);
|
|
64353
|
+
const cc = candByKey.get(ck);
|
|
64354
|
+
if (!pp || !cc || pp.tag !== cc.tag || !sameKindOfBox(pp, cc))
|
|
64355
|
+
break;
|
|
64356
|
+
claims.push({ p: pp, c: cc, dist });
|
|
64357
|
+
p = pp;
|
|
64358
|
+
c = cc;
|
|
64359
|
+
}
|
|
64360
|
+
p = ap;
|
|
64361
|
+
c = ac;
|
|
64362
|
+
for (let dist = 1;; dist++) {
|
|
64363
|
+
const pp = prodKids.get(p.key);
|
|
64364
|
+
const cc = candKids.get(c.key);
|
|
64365
|
+
if (pp?.length !== 1 || cc?.length !== 1)
|
|
64366
|
+
break;
|
|
64367
|
+
const [pn] = pp;
|
|
64368
|
+
const [cn] = cc;
|
|
64369
|
+
if (!pn || !cn || pn.tag !== cn.tag || !sameKindOfBox(pn, cn))
|
|
64370
|
+
break;
|
|
64371
|
+
claims.push({ p: pn, c: cn, dist });
|
|
64372
|
+
p = pn;
|
|
64373
|
+
c = cn;
|
|
64374
|
+
}
|
|
64375
|
+
}
|
|
64376
|
+
const disputed = new Set;
|
|
64377
|
+
const partners = new Map;
|
|
64378
|
+
for (const { p, c, dist } of claims) {
|
|
64379
|
+
for (const [a, b] of [
|
|
64380
|
+
[`p:${p.key}:${dist}`, c.key],
|
|
64381
|
+
[`c:${c.key}:${dist}`, p.key]
|
|
64382
|
+
]) {
|
|
64383
|
+
const set = partners.get(a) ?? new Set;
|
|
64384
|
+
set.add(b);
|
|
64385
|
+
partners.set(a, set);
|
|
64386
|
+
if (set.size > 1)
|
|
64387
|
+
disputed.add(a);
|
|
64388
|
+
}
|
|
64389
|
+
}
|
|
64390
|
+
claims.sort((a, b) => a.dist - b.dist);
|
|
64391
|
+
const pairs = [];
|
|
64392
|
+
for (const { p, c, dist } of claims) {
|
|
64393
|
+
if (usedP.has(p) || usedC.has(c))
|
|
64394
|
+
continue;
|
|
64395
|
+
if (disputed.has(`p:${p.key}:${dist}`) || disputed.has(`c:${c.key}:${dist}`))
|
|
64396
|
+
continue;
|
|
64397
|
+
pairs.push([p, c]);
|
|
64398
|
+
usedP.add(p);
|
|
64399
|
+
usedC.add(c);
|
|
64400
|
+
}
|
|
64401
|
+
return pairs;
|
|
64402
|
+
}
|
|
64403
|
+
function alignBoxTrees(prod, cand, aliases) {
|
|
64404
|
+
const prodByKey = indexByKey(prod);
|
|
64405
|
+
const candByKey = indexByKey(cand);
|
|
64406
|
+
const usedP = new Set;
|
|
64407
|
+
const usedC = new Set;
|
|
64408
|
+
const anchors = anchorPairs(prod, cand, aliases, usedP, usedC);
|
|
64409
|
+
const pairs = [
|
|
64410
|
+
...anchors,
|
|
64411
|
+
...propagateAnchors(anchors, prodByKey, candByKey, usedP, usedC)
|
|
64412
|
+
];
|
|
64413
|
+
const lastSegment = (key) => key.slice(key.lastIndexOf(">") + 1);
|
|
64414
|
+
const prodKids = childIndex(prod);
|
|
64415
|
+
const candKids = childIndex(cand);
|
|
64416
|
+
const queue = [
|
|
64417
|
+
[VIRTUAL_ROOT, VIRTUAL_ROOT],
|
|
64418
|
+
...pairs.map(([p, c]) => [p.key, c.key])
|
|
64419
|
+
];
|
|
64420
|
+
for (let i = 0;i < queue.length; i++) {
|
|
64421
|
+
const at = queue[i];
|
|
64422
|
+
if (!at)
|
|
64423
|
+
continue;
|
|
64424
|
+
const [pKey, cKey] = at;
|
|
64425
|
+
const kids = prodKids.get(pKey);
|
|
64426
|
+
const candSiblings = candKids.get(cKey);
|
|
64427
|
+
if (!kids || !candSiblings)
|
|
64428
|
+
continue;
|
|
64429
|
+
const bySegment = new Map;
|
|
64430
|
+
for (const n of candSiblings)
|
|
64431
|
+
if (!usedC.has(n))
|
|
64432
|
+
bySegment.set(lastSegment(n.key), n);
|
|
64433
|
+
for (const pn of kids) {
|
|
64434
|
+
if (usedP.has(pn))
|
|
64435
|
+
continue;
|
|
64436
|
+
const cn = bySegment.get(lastSegment(pn.key));
|
|
64437
|
+
if (!cn || usedC.has(cn))
|
|
64438
|
+
continue;
|
|
64439
|
+
if (!sameKindOfBox(pn, cn))
|
|
64440
|
+
continue;
|
|
64441
|
+
pairs.push([pn, cn]);
|
|
64442
|
+
usedP.add(pn);
|
|
64443
|
+
usedC.add(cn);
|
|
64444
|
+
queue.push([pn.key, cn.key]);
|
|
63713
64445
|
}
|
|
63714
64446
|
}
|
|
63715
64447
|
return {
|
|
63716
64448
|
pairs,
|
|
63717
|
-
onlyInProd:
|
|
63718
|
-
onlyInCand: cand.filter((c) => !
|
|
64449
|
+
onlyInProd: prod.filter((p) => !usedP.has(p)),
|
|
64450
|
+
onlyInCand: cand.filter((c) => !usedC.has(c))
|
|
63719
64451
|
};
|
|
63720
64452
|
}
|
|
63721
64453
|
function rectProps(n) {
|
|
@@ -63729,9 +64461,22 @@ function rectProps(n) {
|
|
|
63729
64461
|
function diffBoxTrees(prod, cand, opts = {}) {
|
|
63730
64462
|
const tolerancePx = opts.tolerancePx ?? 1;
|
|
63731
64463
|
const maxDeltas = opts.maxDeltas ?? 200;
|
|
63732
|
-
const { pairs, onlyInProd, onlyInCand } = alignBoxTrees(prod, cand);
|
|
64464
|
+
const { pairs, onlyInProd, onlyInCand } = alignBoxTrees(prod, cand, opts.aliases);
|
|
63733
64465
|
const deltas = [];
|
|
63734
64466
|
for (const [p, c] of pairs) {
|
|
64467
|
+
if (isVisuallyHidden(p) !== isVisuallyHidden(c)) {
|
|
64468
|
+
const hiddenOnProd = isVisuallyHidden(p);
|
|
64469
|
+
deltas.push({
|
|
64470
|
+
key: p.key,
|
|
64471
|
+
label: p.label,
|
|
64472
|
+
prop: "visually-hidden",
|
|
64473
|
+
prod: hiddenOnProd ? "yes" : "no",
|
|
64474
|
+
cand: hiddenOnProd ? "no" : "yes",
|
|
64475
|
+
deltaPx: null,
|
|
64476
|
+
weight: STRUCTURAL_CHANGE_WEIGHT
|
|
64477
|
+
});
|
|
64478
|
+
continue;
|
|
64479
|
+
}
|
|
63735
64480
|
const pAll = { ...p.styles, ...rectProps(p) };
|
|
63736
64481
|
const cAll = { ...c.styles, ...rectProps(c) };
|
|
63737
64482
|
for (const prop of Object.keys(pAll)) {
|
|
@@ -63752,10 +64497,11 @@ function diffBoxTrees(prod, cand, opts = {}) {
|
|
|
63752
64497
|
prod: a,
|
|
63753
64498
|
cand: b,
|
|
63754
64499
|
deltaPx: d,
|
|
63755
|
-
weight:
|
|
64500
|
+
weight: isTypeChange(prop, p) ? TYPE_CHANGE_WEIGHT + pxWeight(d) : pxWeight(d)
|
|
63756
64501
|
});
|
|
63757
64502
|
continue;
|
|
63758
64503
|
}
|
|
64504
|
+
const weight = isTypeChange(prop, p) ? TYPE_CHANGE_WEIGHT : STRUCTURAL_PROPS.has(prop) ? STRUCTURAL_CHANGE_WEIGHT : VALUE_CHANGE_WEIGHT;
|
|
63759
64505
|
deltas.push({
|
|
63760
64506
|
key: p.key,
|
|
63761
64507
|
label: p.label,
|
|
@@ -63763,25 +64509,39 @@ function diffBoxTrees(prod, cand, opts = {}) {
|
|
|
63763
64509
|
prod: a || "(empty)",
|
|
63764
64510
|
cand: b || "(empty)",
|
|
63765
64511
|
deltaPx: null,
|
|
63766
|
-
weight
|
|
64512
|
+
weight
|
|
63767
64513
|
});
|
|
63768
64514
|
}
|
|
63769
64515
|
}
|
|
63770
64516
|
deltas.sort((x, y) => y.weight - x.weight || x.key.localeCompare(y.key) || x.prop.localeCompare(y.prop));
|
|
63771
|
-
const
|
|
64517
|
+
const pairedKeys = { prod: pairs.map(([p]) => p.key), cand: pairs.map(([, c]) => c.key) };
|
|
64518
|
+
const brief = (side) => (n) => ({
|
|
64519
|
+
key: n.key,
|
|
64520
|
+
label: n.label,
|
|
64521
|
+
tag: n.tag,
|
|
64522
|
+
contentsPaired: pairedKeys[side].some((k) => k.startsWith(`${n.key}>`))
|
|
64523
|
+
});
|
|
63772
64524
|
return {
|
|
63773
64525
|
matched: pairs.length,
|
|
63774
|
-
onlyInProd: onlyInProd.map(brief),
|
|
63775
|
-
onlyInCand: onlyInCand.map(brief),
|
|
64526
|
+
onlyInProd: onlyInProd.map(brief("prod")),
|
|
64527
|
+
onlyInCand: onlyInCand.map(brief("cand")),
|
|
63776
64528
|
deltas: deltas.slice(0, maxDeltas),
|
|
63777
64529
|
truncated: opts.truncated ?? false
|
|
63778
64530
|
};
|
|
63779
64531
|
}
|
|
64532
|
+
function isBoxTreeInconclusive(diff) {
|
|
64533
|
+
const prodNodes = diff.matched + diff.onlyInProd.length;
|
|
64534
|
+
const candNodes = diff.matched + diff.onlyInCand.length;
|
|
64535
|
+
return prodNodes <= 1 && candNodes <= 1 && diff.deltas.length === 0;
|
|
64536
|
+
}
|
|
63780
64537
|
function isGeometryClean(diff) {
|
|
63781
|
-
return diff.deltas.length === 0 && diff.onlyInProd.length === 0 && diff.onlyInCand.length === 0;
|
|
64538
|
+
return !isBoxTreeInconclusive(diff) && diff.deltas.length === 0 && diff.onlyInProd.length === 0 && diff.onlyInCand.length === 0;
|
|
63782
64539
|
}
|
|
63783
64540
|
function formatBoxTreeDiff(diff, opts = {}) {
|
|
63784
64541
|
const limit = opts.limit ?? 40;
|
|
64542
|
+
if (isBoxTreeInconclusive(diff)) {
|
|
64543
|
+
return `geometry: INCONCLUSIVE — ${diff.matched} node(s) paired, so nothing was compared. Check that both selectors match something with content.`;
|
|
64544
|
+
}
|
|
63785
64545
|
if (isGeometryClean(diff)) {
|
|
63786
64546
|
return `geometry: clean (${diff.matched} nodes matched)${diff.truncated ? " — TRUNCATED, absence is not proof" : ""}`;
|
|
63787
64547
|
}
|
|
@@ -63797,12 +64557,11 @@ function formatBoxTreeDiff(diff, opts = {}) {
|
|
|
63797
64557
|
if (diff.deltas.length > shown.length) {
|
|
63798
64558
|
lines.push(`… ${diff.deltas.length - shown.length} more`);
|
|
63799
64559
|
}
|
|
63800
|
-
|
|
63801
|
-
|
|
63802
|
-
|
|
63803
|
-
for (const n of diff.onlyInCand)
|
|
63804
|
-
lines.push(
|
|
63805
|
-
}
|
|
64560
|
+
const unmatched = (n, side) => `${n.key.padEnd(keyW)} ${"—".padEnd(propW)} ${n.contentsPaired ? `wrapper only in ${side} — its contents paired` : `only in ${side}`}${n.label ? ` (${n.label})` : ""}`;
|
|
64561
|
+
for (const n of diff.onlyInProd)
|
|
64562
|
+
lines.push(unmatched(n, "prod"));
|
|
64563
|
+
for (const n of diff.onlyInCand)
|
|
64564
|
+
lines.push(unmatched(n, "cand"));
|
|
63806
64565
|
if (diff.truncated)
|
|
63807
64566
|
lines.push("TRUNCATED — node cap hit; absence of a delta is not proof");
|
|
63808
64567
|
return lines.join(`
|
|
@@ -63858,6 +64617,8 @@ var BOX_TREE_KEYS = [
|
|
|
63858
64617
|
"transform"
|
|
63859
64618
|
];
|
|
63860
64619
|
var LABEL_ATTRS = ["data-section", "data-testid", "data-fs-section", "data-manifest-key", "id"];
|
|
64620
|
+
var GENERATED_ID = /^(?::[rR][0-9a-zA-Z]*:|_[rR]_[0-9a-zA-Z_]*_)$/;
|
|
64621
|
+
var NON_RENDERED = ["script", "style", "link", "meta", "template", "noscript", "title", "head"];
|
|
63861
64622
|
async function readBoxTree(page, selector, opts = {}) {
|
|
63862
64623
|
const maxDepth = opts.maxDepth ?? 12;
|
|
63863
64624
|
const maxNodes = opts.maxNodes ?? 400;
|
|
@@ -63874,7 +64635,7 @@ async function readBoxTree(page, selector, opts = {}) {
|
|
|
63874
64635
|
}
|
|
63875
64636
|
let got;
|
|
63876
64637
|
try {
|
|
63877
|
-
got = await page.evaluate(({ sel, keys, maxDepth, maxNodes, skipZeroArea, labelAttrs }) => {
|
|
64638
|
+
got = await page.evaluate(({ sel, keys, maxDepth, maxNodes, skipZeroArea, labelAttrs, skipTags, generatedIdPattern }) => {
|
|
63878
64639
|
try {
|
|
63879
64640
|
const root = document.querySelector(sel);
|
|
63880
64641
|
if (!root || !(root instanceof HTMLElement)) {
|
|
@@ -63883,14 +64644,19 @@ async function readBoxTree(page, selector, opts = {}) {
|
|
|
63883
64644
|
const origin = root.getBoundingClientRect();
|
|
63884
64645
|
const nodes = [];
|
|
63885
64646
|
let truncated = false;
|
|
64647
|
+
const generatedId = new RegExp(generatedIdPattern);
|
|
63886
64648
|
const labelOf = (el) => {
|
|
63887
64649
|
for (const a of labelAttrs) {
|
|
63888
64650
|
const v = el.getAttribute(a);
|
|
63889
|
-
if (v)
|
|
63890
|
-
|
|
64651
|
+
if (!v)
|
|
64652
|
+
continue;
|
|
64653
|
+
if (a === "id" && generatedId.test(v))
|
|
64654
|
+
continue;
|
|
64655
|
+
return v;
|
|
63891
64656
|
}
|
|
63892
64657
|
return null;
|
|
63893
64658
|
};
|
|
64659
|
+
const skip = new Set(skipTags);
|
|
63894
64660
|
const walk = (el, path, depth) => {
|
|
63895
64661
|
if (nodes.length >= maxNodes) {
|
|
63896
64662
|
truncated = true;
|
|
@@ -63927,6 +64693,8 @@ async function readBoxTree(page, selector, opts = {}) {
|
|
|
63927
64693
|
const perTag = {};
|
|
63928
64694
|
for (const child of Array.from(el.children)) {
|
|
63929
64695
|
const t = child.tagName.toLowerCase();
|
|
64696
|
+
if (skip.has(t))
|
|
64697
|
+
continue;
|
|
63930
64698
|
const i = perTag[t] ?? 0;
|
|
63931
64699
|
perTag[t] = i + 1;
|
|
63932
64700
|
walk(child, `${path}>${t}[${i}]`, depth + 1);
|
|
@@ -63940,7 +64708,16 @@ async function readBoxTree(page, selector, opts = {}) {
|
|
|
63940
64708
|
reason: `walk falhou em '${sel}': ${err.message ?? "unknown"}`
|
|
63941
64709
|
};
|
|
63942
64710
|
}
|
|
63943
|
-
}, {
|
|
64711
|
+
}, {
|
|
64712
|
+
sel: selector,
|
|
64713
|
+
keys,
|
|
64714
|
+
maxDepth,
|
|
64715
|
+
maxNodes,
|
|
64716
|
+
skipZeroArea,
|
|
64717
|
+
labelAttrs: LABEL_ATTRS,
|
|
64718
|
+
skipTags: NON_RENDERED,
|
|
64719
|
+
generatedIdPattern: GENERATED_ID.source
|
|
64720
|
+
});
|
|
63944
64721
|
} catch (err) {
|
|
63945
64722
|
return {
|
|
63946
64723
|
found: false,
|
|
@@ -63994,6 +64771,9 @@ async function sectionCommand(opts) {
|
|
|
63994
64771
|
cand: resolve3(opts.outDir, `${filePrefix}-cand.png`)
|
|
63995
64772
|
};
|
|
63996
64773
|
const heatmapPath = resolve3(opts.outDir, `${filePrefix}-heatmap.png`);
|
|
64774
|
+
const { aliases, note: aliasNote } = resolveAliases(opts.planDir);
|
|
64775
|
+
if (aliasNote)
|
|
64776
|
+
console.log(chalk14.dim(` ${aliasNote}`));
|
|
63997
64777
|
const browser = await launchBrowser({ headless: true });
|
|
63998
64778
|
try {
|
|
63999
64779
|
const [prodSide, candSide] = await Promise.all([
|
|
@@ -64023,7 +64803,7 @@ async function sectionCommand(opts) {
|
|
|
64023
64803
|
})
|
|
64024
64804
|
]);
|
|
64025
64805
|
const heatmap = want.heatmap ? computeHeatmap(prodSide, candSide, screenshotPaths, heatmapPath) : null;
|
|
64026
|
-
const boxTree = computeBoxTreeDiff(prodSide, candSide);
|
|
64806
|
+
const boxTree = computeBoxTreeDiff(prodSide, candSide, aliases);
|
|
64027
64807
|
const bundlePaths = want.prompt ? await buildPromptBundle({
|
|
64028
64808
|
opts,
|
|
64029
64809
|
viewport,
|
|
@@ -64064,6 +64844,14 @@ async function sectionCommand(opts) {
|
|
|
64064
64844
|
await printResults2({ opts, viewport, candSelector, prodSide, candSide, screenshotPaths, want });
|
|
64065
64845
|
if (boxTree)
|
|
64066
64846
|
printBoxTree(boxTree);
|
|
64847
|
+
for (const [side, data] of [
|
|
64848
|
+
["prod", prodSide],
|
|
64849
|
+
["cand", candSide]
|
|
64850
|
+
]) {
|
|
64851
|
+
const caveat = data.settle && formatSettleCaveat(side, data.settle);
|
|
64852
|
+
if (caveat)
|
|
64853
|
+
console.log(chalk14.yellow(` ${caveat}`));
|
|
64854
|
+
}
|
|
64067
64855
|
if (heatmap)
|
|
64068
64856
|
printHeatmap(heatmap, heatmapPath);
|
|
64069
64857
|
if (bundlePaths)
|
|
@@ -64077,7 +64865,7 @@ async function sectionCommand(opts) {
|
|
|
64077
64865
|
});
|
|
64078
64866
|
}
|
|
64079
64867
|
}
|
|
64080
|
-
function computeBoxTreeDiff(prodSide, candSide) {
|
|
64868
|
+
function computeBoxTreeDiff(prodSide, candSide, aliases) {
|
|
64081
64869
|
const p = prodSide.boxTree;
|
|
64082
64870
|
const c = candSide.boxTree;
|
|
64083
64871
|
if (!p || !c)
|
|
@@ -64086,7 +64874,7 @@ function computeBoxTreeDiff(prodSide, candSide) {
|
|
|
64086
64874
|
return { error: `prod: ${p.error}` };
|
|
64087
64875
|
if (!c.found)
|
|
64088
64876
|
return { error: `cand: ${c.error}` };
|
|
64089
|
-
return diffBoxTrees(p.nodes, c.nodes, { truncated: p.truncated || c.truncated });
|
|
64877
|
+
return diffBoxTrees(p.nodes, c.nodes, { truncated: p.truncated || c.truncated, aliases });
|
|
64090
64878
|
}
|
|
64091
64879
|
function printBoxTree(result) {
|
|
64092
64880
|
console.log("");
|
|
@@ -64115,6 +64903,8 @@ async function gatherSide(browser, opts) {
|
|
|
64115
64903
|
});
|
|
64116
64904
|
if (opts.waitMs > 0)
|
|
64117
64905
|
await page.waitForTimeout(opts.waitMs);
|
|
64906
|
+
await reloadIfOptionalFonts(page, opts.waitMs);
|
|
64907
|
+
result.settle = await waitForLayoutStable(page);
|
|
64118
64908
|
await Promise.race([
|
|
64119
64909
|
stabilizeCarousels(page).catch(() => {
|
|
64120
64910
|
return;
|
|
@@ -64955,8 +65745,8 @@ function formatPatch(patch) {
|
|
|
64955
65745
|
}
|
|
64956
65746
|
|
|
64957
65747
|
// src/commands/journey.ts
|
|
64958
|
-
import { writeFileSync as
|
|
64959
|
-
import { join as
|
|
65748
|
+
import { writeFileSync as writeFileSync22 } from "node:fs";
|
|
65749
|
+
import { join as join26 } from "node:path";
|
|
64960
65750
|
import chalk17 from "chalk";
|
|
64961
65751
|
import ora7 from "ora";
|
|
64962
65752
|
init_client();
|
|
@@ -65026,7 +65816,7 @@ async function journeyCommand(opts) {
|
|
|
65026
65816
|
};
|
|
65027
65817
|
async function runOneSide(browserInstance, viewport, side) {
|
|
65028
65818
|
const baseUrl = side === "prod" ? opts.prod : opts.cand;
|
|
65029
|
-
const tracePath =
|
|
65819
|
+
const tracePath = join26(paths.tracesDir, `${viewport}-${side}.zip`);
|
|
65030
65820
|
const ctx = await newContext(browserInstance, {
|
|
65031
65821
|
viewport,
|
|
65032
65822
|
tracesDir: paths.tracesDir,
|
|
@@ -65118,7 +65908,7 @@ async function journeyCommand(opts) {
|
|
|
65118
65908
|
if (opts.github)
|
|
65119
65909
|
emitGithubAnnotations(failures);
|
|
65120
65910
|
if (opts.junit) {
|
|
65121
|
-
|
|
65911
|
+
writeFileSync22(opts.junit, buildJUnit(rows, failures), "utf8");
|
|
65122
65912
|
if (!opts.json)
|
|
65123
65913
|
console.log(chalk17.dim(` → JUnit XML: ${opts.junit}`));
|
|
65124
65914
|
}
|
|
@@ -65666,19 +66456,19 @@ async function nodeFetchText(url) {
|
|
|
65666
66456
|
}
|
|
65667
66457
|
|
|
65668
66458
|
// src/migrate/exporters/json.ts
|
|
65669
|
-
import { writeFileSync as
|
|
65670
|
-
import { join as
|
|
66459
|
+
import { writeFileSync as writeFileSync23 } from "node:fs";
|
|
66460
|
+
import { join as join27 } from "node:path";
|
|
65671
66461
|
var jsonExporter2 = {
|
|
65672
66462
|
name: "json",
|
|
65673
66463
|
async export(bundle, outDir) {
|
|
65674
|
-
|
|
66464
|
+
writeFileSync23(join27(outDir, "manifest.json"), `${JSON.stringify(bundle, null, 2)}
|
|
65675
66465
|
`, "utf8");
|
|
65676
66466
|
}
|
|
65677
66467
|
};
|
|
65678
66468
|
|
|
65679
66469
|
// src/migrate/exporters/markdown.ts
|
|
65680
|
-
import { mkdirSync as mkdirSync16, writeFileSync as
|
|
65681
|
-
import { join as
|
|
66470
|
+
import { mkdirSync as mkdirSync16, writeFileSync as writeFileSync24 } from "node:fs";
|
|
66471
|
+
import { join as join28 } from "node:path";
|
|
65682
66472
|
var markdownExporter2 = {
|
|
65683
66473
|
name: "markdown",
|
|
65684
66474
|
async export(bundle, outDir) {
|
|
@@ -65686,16 +66476,16 @@ var markdownExporter2 = {
|
|
|
65686
66476
|
const notes = [];
|
|
65687
66477
|
bundle.components.forEach((component, i) => {
|
|
65688
66478
|
const dirName = dirNames[i];
|
|
65689
|
-
const componentDir =
|
|
66479
|
+
const componentDir = join28(outDir, "components", dirName);
|
|
65690
66480
|
mkdirSync16(componentDir, { recursive: true });
|
|
65691
66481
|
const compact = compactComponentHtml(component.html);
|
|
65692
66482
|
if (compact.collapsed > 0)
|
|
65693
66483
|
notes.push(`\`${dirName}\`: collapsed ${compact.collapsed} repeated child element(s)`);
|
|
65694
66484
|
if (compact.truncated)
|
|
65695
66485
|
notes.push(`\`${dirName}\`: HTML truncated to fit the per-component token ceiling`);
|
|
65696
|
-
|
|
66486
|
+
writeFileSync24(join28(componentDir, "README.md"), renderComponentReadme2(bundle.url, component, compact.html), "utf8");
|
|
65697
66487
|
});
|
|
65698
|
-
|
|
66488
|
+
writeFileSync24(join28(outDir, "index.md"), renderIndex2(bundle, notes), "utf8");
|
|
65699
66489
|
}
|
|
65700
66490
|
};
|
|
65701
66491
|
function renderIndex2(bundle, notes) {
|
|
@@ -65897,8 +66687,8 @@ function escapePipes2(s) {
|
|
|
65897
66687
|
}
|
|
65898
66688
|
|
|
65899
66689
|
// src/migrate/exporters/html.ts
|
|
65900
|
-
import { readFileSync as
|
|
65901
|
-
import { join as
|
|
66690
|
+
import { readFileSync as readFileSync22, writeFileSync as writeFileSync25 } from "node:fs";
|
|
66691
|
+
import { join as join29 } from "node:path";
|
|
65902
66692
|
|
|
65903
66693
|
// src/migrate/targets/faststore-v4.ts
|
|
65904
66694
|
function pickBreakpointTiers(breakpoints) {
|
|
@@ -66218,9 +67008,9 @@ var TARGET_NAMES = Object.keys(TARGETS);
|
|
|
66218
67008
|
var htmlExporter = {
|
|
66219
67009
|
name: "html",
|
|
66220
67010
|
async export(bundle, outDir) {
|
|
66221
|
-
|
|
66222
|
-
const inline = (p) => p ? dataUri2(
|
|
66223
|
-
|
|
67011
|
+
writeFileSync25(join29(outDir, "index.html"), renderHtml(bundle, (p) => p ?? null), "utf8");
|
|
67012
|
+
const inline = (p) => p ? dataUri2(join29(outDir, p)) ?? p : null;
|
|
67013
|
+
writeFileSync25(join29(outDir, "report.html"), renderHtml(bundle, inline), "utf8");
|
|
66224
67014
|
}
|
|
66225
67015
|
};
|
|
66226
67016
|
var MIME2 = {
|
|
@@ -66238,7 +67028,7 @@ function dataUri2(absPath) {
|
|
|
66238
67028
|
const mime = MIME2[ext];
|
|
66239
67029
|
if (!mime)
|
|
66240
67030
|
return null;
|
|
66241
|
-
return `data:${mime};base64,${
|
|
67031
|
+
return `data:${mime};base64,${readFileSync22(absPath).toString("base64")}`;
|
|
66242
67032
|
} catch {
|
|
66243
67033
|
return null;
|
|
66244
67034
|
}
|
|
@@ -66486,353 +67276,6 @@ function buildMigrationPrompt(bundle, playbook, source) {
|
|
|
66486
67276
|
`);
|
|
66487
67277
|
}
|
|
66488
67278
|
|
|
66489
|
-
// src/migrate/plan.ts
|
|
66490
|
-
import { existsSync as existsSync16, readFileSync as readFileSync22, writeFileSync as writeFileSync25 } from "node:fs";
|
|
66491
|
-
import { join as join29 } from "node:path";
|
|
66492
|
-
function dedupe(names) {
|
|
66493
|
-
return [...new Set(names)];
|
|
66494
|
-
}
|
|
66495
|
-
function key(name) {
|
|
66496
|
-
return name.toLowerCase().replace(/[\s_/-]+/g, "");
|
|
66497
|
-
}
|
|
66498
|
-
function buildMigrationPlan(input) {
|
|
66499
|
-
const { bundle, source, inventory } = input;
|
|
66500
|
-
const liveByKey = new Map;
|
|
66501
|
-
for (const c of bundle.components) {
|
|
66502
|
-
liveByKey.set(key(c.role), { role: c.role, scope: c.scope, selector: c.selector });
|
|
66503
|
-
}
|
|
66504
|
-
const srcByKey = new Map;
|
|
66505
|
-
for (const c of inventory.components)
|
|
66506
|
-
srcByKey.set(key(c.name), c);
|
|
66507
|
-
const components = [];
|
|
66508
|
-
for (const [k, c] of srcByKey) {
|
|
66509
|
-
components.push({
|
|
66510
|
-
name: c.name,
|
|
66511
|
-
role: c.role,
|
|
66512
|
-
scope: c.scope,
|
|
66513
|
-
origin: liveByKey.has(k) ? "both" : "source-only",
|
|
66514
|
-
status: "pending",
|
|
66515
|
-
file: c.file,
|
|
66516
|
-
selector: liveByKey.get(k)?.selector ?? null,
|
|
66517
|
-
reference: null,
|
|
66518
|
-
verified: null
|
|
66519
|
-
});
|
|
66520
|
-
}
|
|
66521
|
-
for (const [k, c] of liveByKey) {
|
|
66522
|
-
if (srcByKey.has(k))
|
|
66523
|
-
continue;
|
|
66524
|
-
components.push({
|
|
66525
|
-
name: c.role,
|
|
66526
|
-
role: c.role,
|
|
66527
|
-
scope: c.scope,
|
|
66528
|
-
origin: "live-only",
|
|
66529
|
-
status: "pending",
|
|
66530
|
-
file: null,
|
|
66531
|
-
selector: c.selector,
|
|
66532
|
-
reference: null,
|
|
66533
|
-
verified: null
|
|
66534
|
-
});
|
|
66535
|
-
}
|
|
66536
|
-
return {
|
|
66537
|
-
url: bundle.url,
|
|
66538
|
-
timestamp: bundle.timestamp,
|
|
66539
|
-
source: {
|
|
66540
|
-
kind: source.kind,
|
|
66541
|
-
label: source.label,
|
|
66542
|
-
dir: source.dir,
|
|
66543
|
-
notes: inventory.notes,
|
|
66544
|
-
...input.searched ? { searched: input.searched } : {},
|
|
66545
|
-
...input.project ? { project: input.project } : {}
|
|
66546
|
-
},
|
|
66547
|
-
target: { name: bundle.target ?? null },
|
|
66548
|
-
pages: bundle.pages.map((p) => ({
|
|
66549
|
-
path: p.path,
|
|
66550
|
-
kind: p.kind,
|
|
66551
|
-
status: "pending",
|
|
66552
|
-
components: dedupe((p.components ?? []).map((c) => components.find((row) => key(row.name) === key(c.role))?.name ?? c.role))
|
|
66553
|
-
})),
|
|
66554
|
-
components
|
|
66555
|
-
};
|
|
66556
|
-
}
|
|
66557
|
-
function mergePlanDecisions(fresh, previous) {
|
|
66558
|
-
if (!previous)
|
|
66559
|
-
return { plan: fresh, carried: [], droppedWithDecisions: [] };
|
|
66560
|
-
const prevByKey = new Map(previous.components.map((c) => [key(c.name), c]));
|
|
66561
|
-
const carried = [];
|
|
66562
|
-
for (const row of fresh.components) {
|
|
66563
|
-
const prev = prevByKey.get(key(row.name));
|
|
66564
|
-
if (!prev)
|
|
66565
|
-
continue;
|
|
66566
|
-
if (prev.status !== "pending")
|
|
66567
|
-
row.status = prev.status;
|
|
66568
|
-
if (prev.reference)
|
|
66569
|
-
row.reference = prev.reference;
|
|
66570
|
-
if (prev.verified)
|
|
66571
|
-
row.verified = prev.verified;
|
|
66572
|
-
if (prev.status !== "pending" || prev.reference || prev.verified)
|
|
66573
|
-
carried.push(row.name);
|
|
66574
|
-
}
|
|
66575
|
-
const freshKeys = new Set(fresh.components.map((c) => key(c.name)));
|
|
66576
|
-
const droppedWithDecisions = previous.components.filter((c) => !freshKeys.has(key(c.name))).filter((c) => c.status !== "pending" || Boolean(c.reference) || Boolean(c.verified)).map((c) => c.name);
|
|
66577
|
-
const prevPages = new Map(previous.pages.map((p) => [p.path, p]));
|
|
66578
|
-
for (const page of fresh.pages) {
|
|
66579
|
-
const prev = prevPages.get(page.path);
|
|
66580
|
-
if (prev?.status && prev.status !== "pending")
|
|
66581
|
-
page.status = prev.status;
|
|
66582
|
-
if (prev?.boardItemId)
|
|
66583
|
-
page.boardItemId = prev.boardItemId;
|
|
66584
|
-
}
|
|
66585
|
-
return { plan: fresh, carried, droppedWithDecisions };
|
|
66586
|
-
}
|
|
66587
|
-
var PLAN_FILE = "migration-plan.json";
|
|
66588
|
-
var SETTLED = new Set(["done", "as-is", "upgrade", "skipped"]);
|
|
66589
|
-
function loadPlan(dir) {
|
|
66590
|
-
const p = join29(dir, PLAN_FILE);
|
|
66591
|
-
if (!existsSync16(p))
|
|
66592
|
-
return null;
|
|
66593
|
-
return JSON.parse(readFileSync22(p, "utf8"));
|
|
66594
|
-
}
|
|
66595
|
-
function savePlan(dir, plan) {
|
|
66596
|
-
writeFileSync25(join29(dir, PLAN_FILE), `${JSON.stringify(plan, null, 2)}
|
|
66597
|
-
`, "utf8");
|
|
66598
|
-
}
|
|
66599
|
-
function setComponentStatus(plan, name, status) {
|
|
66600
|
-
const k = key(name);
|
|
66601
|
-
const component = plan.components.find((c) => key(c.name) === k);
|
|
66602
|
-
if (!component)
|
|
66603
|
-
return null;
|
|
66604
|
-
component.status = status;
|
|
66605
|
-
return component;
|
|
66606
|
-
}
|
|
66607
|
-
function setPageStatus(plan, path, status) {
|
|
66608
|
-
const page = findPage(plan, path);
|
|
66609
|
-
if (!page)
|
|
66610
|
-
return null;
|
|
66611
|
-
page.status = status;
|
|
66612
|
-
return page;
|
|
66613
|
-
}
|
|
66614
|
-
function findPage(plan, path) {
|
|
66615
|
-
const norm = (p) => `/${p.trim().replace(/^\/+|\/+$/g, "")}` || "/";
|
|
66616
|
-
const target = norm(path);
|
|
66617
|
-
return plan.pages.find((p) => p.path === path) ?? plan.pages.find((p) => norm(p.path) === target) ?? null;
|
|
66618
|
-
}
|
|
66619
|
-
function setPageBoardItemId(plan, path, boardItemId) {
|
|
66620
|
-
const page = findPage(plan, path);
|
|
66621
|
-
if (!page)
|
|
66622
|
-
return null;
|
|
66623
|
-
page.boardItemId = boardItemId;
|
|
66624
|
-
return page;
|
|
66625
|
-
}
|
|
66626
|
-
function planProgress(plan) {
|
|
66627
|
-
const compByStatus = {
|
|
66628
|
-
pending: 0,
|
|
66629
|
-
partial: 0,
|
|
66630
|
-
done: 0,
|
|
66631
|
-
"as-is": 0,
|
|
66632
|
-
upgrade: 0,
|
|
66633
|
-
skipped: 0
|
|
66634
|
-
};
|
|
66635
|
-
const settled = [];
|
|
66636
|
-
const settledByStatus = { done: [], skipped: [] };
|
|
66637
|
-
const accepted = { asIs: [], upgrade: [] };
|
|
66638
|
-
const remaining = [];
|
|
66639
|
-
for (const c of plan.components) {
|
|
66640
|
-
compByStatus[c.status] = (compByStatus[c.status] ?? 0) + 1;
|
|
66641
|
-
if (c.status === "as-is")
|
|
66642
|
-
accepted.asIs.push(c.name);
|
|
66643
|
-
if (c.status === "upgrade")
|
|
66644
|
-
accepted.upgrade.push(c.name);
|
|
66645
|
-
if (c.status === "done")
|
|
66646
|
-
settledByStatus.done.push(c.name);
|
|
66647
|
-
if (c.status === "skipped")
|
|
66648
|
-
settledByStatus.skipped.push(c.name);
|
|
66649
|
-
if (SETTLED.has(c.status))
|
|
66650
|
-
settled.push(c.name);
|
|
66651
|
-
else
|
|
66652
|
-
remaining.push({
|
|
66653
|
-
name: c.name,
|
|
66654
|
-
status: c.status,
|
|
66655
|
-
scope: c.scope ?? "page",
|
|
66656
|
-
origin: c.origin
|
|
66657
|
-
});
|
|
66658
|
-
}
|
|
66659
|
-
const pageByStatus = { pending: 0, code: 0, done: 0, skipped: 0 };
|
|
66660
|
-
const awaitingContent = [];
|
|
66661
|
-
const pagesRemaining = [];
|
|
66662
|
-
for (const p of plan.pages) {
|
|
66663
|
-
const status = p.status ?? "pending";
|
|
66664
|
-
pageByStatus[status] = (pageByStatus[status] ?? 0) + 1;
|
|
66665
|
-
if (status === "code")
|
|
66666
|
-
awaitingContent.push(p.path);
|
|
66667
|
-
if (status !== "done" && status !== "skipped") {
|
|
66668
|
-
pagesRemaining.push({ path: p.path, kind: p.kind, status });
|
|
66669
|
-
}
|
|
66670
|
-
}
|
|
66671
|
-
return {
|
|
66672
|
-
components: {
|
|
66673
|
-
total: plan.components.length,
|
|
66674
|
-
byStatus: compByStatus,
|
|
66675
|
-
settled,
|
|
66676
|
-
settledByStatus,
|
|
66677
|
-
accepted,
|
|
66678
|
-
remaining
|
|
66679
|
-
},
|
|
66680
|
-
pages: {
|
|
66681
|
-
total: plan.pages.length,
|
|
66682
|
-
byStatus: pageByStatus,
|
|
66683
|
-
awaitingContent,
|
|
66684
|
-
remaining: pagesRemaining
|
|
66685
|
-
}
|
|
66686
|
-
};
|
|
66687
|
-
}
|
|
66688
|
-
function joinUrl(base, path) {
|
|
66689
|
-
return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`.replace(/\/$/, "") || base;
|
|
66690
|
-
}
|
|
66691
|
-
function shellQuote(value) {
|
|
66692
|
-
return /^[\w./:=-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
66693
|
-
}
|
|
66694
|
-
function disposition(c) {
|
|
66695
|
-
if (c.status === "pending" || c.status === "partial")
|
|
66696
|
-
return "build";
|
|
66697
|
-
if (c.status === "skipped")
|
|
66698
|
-
return "settled";
|
|
66699
|
-
if (c.status === "as-is")
|
|
66700
|
-
return "as-is";
|
|
66701
|
-
if (c.verified)
|
|
66702
|
-
return "settled";
|
|
66703
|
-
if (c.status === "upgrade")
|
|
66704
|
-
return c.reference ? "validate" : "upgrade";
|
|
66705
|
-
return "validate";
|
|
66706
|
-
}
|
|
66707
|
-
function pagePlan(plan, path, candUrl) {
|
|
66708
|
-
const page = findPage(plan, path);
|
|
66709
|
-
if (!page)
|
|
66710
|
-
return null;
|
|
66711
|
-
const counts = {
|
|
66712
|
-
build: 0,
|
|
66713
|
-
validate: 0,
|
|
66714
|
-
upgrade: 0,
|
|
66715
|
-
"as-is": 0,
|
|
66716
|
-
settled: 0
|
|
66717
|
-
};
|
|
66718
|
-
let tasks = null;
|
|
66719
|
-
if (page.components) {
|
|
66720
|
-
tasks = [];
|
|
66721
|
-
for (const name of page.components) {
|
|
66722
|
-
const c = plan.components.find((row) => key(row.name) === key(name));
|
|
66723
|
-
if (!c)
|
|
66724
|
-
continue;
|
|
66725
|
-
const d = disposition(c);
|
|
66726
|
-
counts[d] += 1;
|
|
66727
|
-
const selector = c.reference?.selector ?? c.selector ?? null;
|
|
66728
|
-
const refUrl = c.reference?.url ?? plan.url;
|
|
66729
|
-
const kind = c.reference ? "reference" : "prod";
|
|
66730
|
-
const checkable = d === "validate" && Boolean(selector) && Boolean(candUrl);
|
|
66731
|
-
tasks.push({
|
|
66732
|
-
name: c.name,
|
|
66733
|
-
disposition: d,
|
|
66734
|
-
status: c.status,
|
|
66735
|
-
scope: c.scope ?? "page",
|
|
66736
|
-
origin: c.origin,
|
|
66737
|
-
selector,
|
|
66738
|
-
against: d === "validate" ? { url: refUrl, kind } : null,
|
|
66739
|
-
command: checkable && candUrl && selector ? `parity section --prod ${shellQuote(joinUrl(refUrl, page.path))} --cand ${shellQuote(joinUrl(candUrl, page.path))} --selector ${shellQuote(selector)}` : null,
|
|
66740
|
-
note: c.reference?.note ?? null
|
|
66741
|
-
});
|
|
66742
|
-
}
|
|
66743
|
-
}
|
|
66744
|
-
return {
|
|
66745
|
-
path: page.path,
|
|
66746
|
-
kind: page.kind,
|
|
66747
|
-
status: page.status ?? "pending",
|
|
66748
|
-
tasks,
|
|
66749
|
-
counts,
|
|
66750
|
-
ready: counts.build === 0 && counts.validate === 0
|
|
66751
|
-
};
|
|
66752
|
-
}
|
|
66753
|
-
function pageColumn(page) {
|
|
66754
|
-
if (page.status === "skipped")
|
|
66755
|
-
return "skipped";
|
|
66756
|
-
if (page.status === "done")
|
|
66757
|
-
return "done";
|
|
66758
|
-
if (page.tasks === null || page.tasks.length === 0)
|
|
66759
|
-
return "triage";
|
|
66760
|
-
if (page.ready)
|
|
66761
|
-
return "review";
|
|
66762
|
-
const started = page.counts.settled + page.counts.validate + page.counts["as-is"] + page.counts.upgrade;
|
|
66763
|
-
return started > 0 ? "building" : "backlog";
|
|
66764
|
-
}
|
|
66765
|
-
function planBoard(plan, candUrl) {
|
|
66766
|
-
const columns = {
|
|
66767
|
-
triage: [],
|
|
66768
|
-
backlog: [],
|
|
66769
|
-
building: [],
|
|
66770
|
-
review: [],
|
|
66771
|
-
done: [],
|
|
66772
|
-
skipped: []
|
|
66773
|
-
};
|
|
66774
|
-
for (const p of plan.pages) {
|
|
66775
|
-
const page = pagePlan(plan, p.path, candUrl);
|
|
66776
|
-
if (!page)
|
|
66777
|
-
continue;
|
|
66778
|
-
const column = pageColumn(page);
|
|
66779
|
-
columns[column].push({
|
|
66780
|
-
path: page.path,
|
|
66781
|
-
kind: page.kind,
|
|
66782
|
-
column,
|
|
66783
|
-
blockers: (page.tasks ?? []).filter((t) => t.disposition === "build" && t.scope !== "global").map((t) => t.name),
|
|
66784
|
-
counts: page.counts,
|
|
66785
|
-
ready: page.ready,
|
|
66786
|
-
boardItemId: p.boardItemId
|
|
66787
|
-
});
|
|
66788
|
-
}
|
|
66789
|
-
const onAnyPage = new Set(plan.pages.flatMap((p) => (p.components ?? []).map(key)));
|
|
66790
|
-
const shell = [];
|
|
66791
|
-
const unassigned = [];
|
|
66792
|
-
for (const c of plan.components) {
|
|
66793
|
-
if (c.scope === "global") {
|
|
66794
|
-
if (disposition(c) === "build")
|
|
66795
|
-
shell.push(c.name);
|
|
66796
|
-
} else if (!onAnyPage.has(key(c.name))) {
|
|
66797
|
-
unassigned.push(c.name);
|
|
66798
|
-
}
|
|
66799
|
-
}
|
|
66800
|
-
return { url: plan.url, columns, shell, unassigned, sampled: plan.pages.length };
|
|
66801
|
-
}
|
|
66802
|
-
function setComponentVerified(plan, name, verdict, at, note) {
|
|
66803
|
-
const k = key(name);
|
|
66804
|
-
const component = plan.components.find((c) => key(c.name) === k);
|
|
66805
|
-
if (!component)
|
|
66806
|
-
return null;
|
|
66807
|
-
const against = component.reference ? "reference" : "prod";
|
|
66808
|
-
component.verified = { at, verdict, against, ...note ? { note } : {} };
|
|
66809
|
-
return component;
|
|
66810
|
-
}
|
|
66811
|
-
function setComponentReference(plan, name, reference) {
|
|
66812
|
-
const k = key(name);
|
|
66813
|
-
const component = plan.components.find((c) => key(c.name) === k);
|
|
66814
|
-
if (!component)
|
|
66815
|
-
return null;
|
|
66816
|
-
component.reference = reference;
|
|
66817
|
-
return component;
|
|
66818
|
-
}
|
|
66819
|
-
function syntheticSourceComponents(plan) {
|
|
66820
|
-
return plan.components.filter((c) => c.origin === "source-only").map((c) => ({
|
|
66821
|
-
role: c.name,
|
|
66822
|
-
selector: "",
|
|
66823
|
-
html: "",
|
|
66824
|
-
computedStyles: null,
|
|
66825
|
-
screenshotPath: "",
|
|
66826
|
-
assets: { images: [], backgroundImages: [], fonts: [] },
|
|
66827
|
-
links: [],
|
|
66828
|
-
textContent: [],
|
|
66829
|
-
tailwind: [],
|
|
66830
|
-
interactions: [],
|
|
66831
|
-
scope: c.scope ?? "page",
|
|
66832
|
-
synthetic: true
|
|
66833
|
-
}));
|
|
66834
|
-
}
|
|
66835
|
-
|
|
66836
67279
|
// src/migrate/sources/deco-fresh.ts
|
|
66837
67280
|
import { existsSync as existsSync17, readFileSync as readFileSync23 } from "node:fs";
|
|
66838
67281
|
import { join as join31 } from "node:path";
|
|
@@ -68103,8 +68546,8 @@ async function migrateCommand(opts) {
|
|
|
68103
68546
|
if (merged.carried.length) {
|
|
68104
68547
|
console.log(chalk20.gray(` plan: carried ${merged.carried.length} recorded decision(s) forward`));
|
|
68105
68548
|
}
|
|
68106
|
-
if (merged.
|
|
68107
|
-
console.log(chalk20.yellow(` plan: ${merged.
|
|
68549
|
+
if (merged.keptUncaptured.length) {
|
|
68550
|
+
console.log(chalk20.yellow(` plan: ${merged.keptUncaptured.length} row(s) kept although this capture no longer sees them — ${merged.keptUncaptured.join(", ")}. They carry a decision or were added by hand; the capture owns the captured row set, not rows it cannot see.`));
|
|
68108
68551
|
}
|
|
68109
68552
|
bundle.components.push(...syntheticSourceComponents(plan));
|
|
68110
68553
|
if (format === "json" || format === "both")
|
|
@@ -68586,7 +69029,7 @@ function fixDescription(fix) {
|
|
|
68586
69029
|
// src/commands/plan.ts
|
|
68587
69030
|
var STATUSES = ["pending", "partial", "done", "as-is", "upgrade", "skipped"];
|
|
68588
69031
|
var PAGE_STATUSES = ["pending", "code", "done", "skipped"];
|
|
68589
|
-
function planSetStatusCommand(dir, name, status) {
|
|
69032
|
+
function planSetStatusCommand(dir, name, status, opts = {}) {
|
|
68590
69033
|
if (!STATUSES.includes(status)) {
|
|
68591
69034
|
console.error(chalk21.red(`Invalid status "${status}". Use one of: ${STATUSES.join(", ")}`));
|
|
68592
69035
|
return 1;
|
|
@@ -68596,11 +69039,16 @@ function planSetStatusCommand(dir, name, status) {
|
|
|
68596
69039
|
console.error(chalk21.red(`No migration-plan.json found in ${dir}`));
|
|
68597
69040
|
return 1;
|
|
68598
69041
|
}
|
|
68599
|
-
const
|
|
69042
|
+
const existed = plan.components.length;
|
|
69043
|
+
const component = setComponentStatus(plan, name, status, opts.create ? { create: { scope: opts.create } } : {});
|
|
68600
69044
|
if (!component) {
|
|
68601
69045
|
console.error(chalk21.red(`No component matching "${name}" in the plan`));
|
|
69046
|
+
console.error(chalk21.yellow("A capture can miss a component that exists — a zero-height overlay header, a portal-rendered panel. Add it with --create global|page if this is one of those, so the plan can hold a decision about it."));
|
|
68602
69047
|
return 1;
|
|
68603
69048
|
}
|
|
69049
|
+
if (plan.components.length > existed) {
|
|
69050
|
+
console.log(chalk21.yellow(` + created ${component.name} (${opts.create}, origin: manual) — not from the capture`));
|
|
69051
|
+
}
|
|
68604
69052
|
savePlan(dir, plan);
|
|
68605
69053
|
console.log(`${chalk21.green("✓")} ${component.name} → ${status}`);
|
|
68606
69054
|
if ((status === "upgrade" || status === "as-is") && !component.reference) {
|
|
@@ -68680,15 +69128,15 @@ function planMergeCommand(dir, sourceDir) {
|
|
|
68680
69128
|
return 1;
|
|
68681
69129
|
}
|
|
68682
69130
|
const existing = loadPlan(dir);
|
|
68683
|
-
const { plan, carried,
|
|
69131
|
+
const { plan, carried, keptUncaptured } = mergePlanDecisions(fresh, existing);
|
|
68684
69132
|
savePlan(dir, plan);
|
|
68685
69133
|
if (!existing) {
|
|
68686
69134
|
console.log(`${chalk21.green("✓")} plan written to ${dir} (nothing to merge)`);
|
|
68687
69135
|
return 0;
|
|
68688
69136
|
}
|
|
68689
69137
|
console.log(`${chalk21.green("✓")} merged into ${dir} — ${carried.length} decision(s) kept`);
|
|
68690
|
-
if (
|
|
68691
|
-
console.log(chalk21.yellow(` no longer in the capture
|
|
69138
|
+
if (keptUncaptured.length) {
|
|
69139
|
+
console.log(chalk21.yellow(` kept although no longer in the capture: ${keptUncaptured.join(", ")}`));
|
|
68692
69140
|
}
|
|
68693
69141
|
return 0;
|
|
68694
69142
|
}
|
|
@@ -68752,8 +69200,10 @@ function planStatusCommand(dir, asJson) {
|
|
|
68752
69200
|
return 1;
|
|
68753
69201
|
}
|
|
68754
69202
|
const p = planProgress(plan);
|
|
69203
|
+
const provenance = provenanceCounts(plan);
|
|
69204
|
+
const touches = totalTouches(plan);
|
|
68755
69205
|
if (asJson) {
|
|
68756
|
-
console.log(JSON.stringify({ url: plan.url, target: plan.target.name, ...p }, null, 2));
|
|
69206
|
+
console.log(JSON.stringify({ url: plan.url, target: plan.target.name, ...p, provenance, touches }, null, 2));
|
|
68757
69207
|
return 0;
|
|
68758
69208
|
}
|
|
68759
69209
|
const c = p.components;
|
|
@@ -68767,6 +69217,13 @@ ${chalk21.bold("Components")} (${c.total}): ` + `${chalk21.green(`${c.byStatus.d
|
|
|
68767
69217
|
if (c.accepted.asIs.length) {
|
|
68768
69218
|
console.log(chalk21.gray(` divergence accepted: ${c.accepted.asIs.join(", ")}`));
|
|
68769
69219
|
}
|
|
69220
|
+
if (provenance.library > 0 || provenance.built > 0) {
|
|
69221
|
+
const unrecorded = provenance.unrecorded > 0 ? chalk21.dim(`, ${provenance.unrecorded} unrecorded`) : "";
|
|
69222
|
+
console.log(` reuse: ${chalk21.green(`${provenance.library} from the library`)}, ${provenance.built} written here${unrecorded}`);
|
|
69223
|
+
}
|
|
69224
|
+
if (touches > 0) {
|
|
69225
|
+
console.log(chalk21.dim(` human touches: ${touches} across this migration`));
|
|
69226
|
+
}
|
|
68770
69227
|
if (c.settledByStatus.done.length) {
|
|
68771
69228
|
console.log(chalk21.green(` ported and validated: ${c.settledByStatus.done.join(", ")}`));
|
|
68772
69229
|
}
|
|
@@ -68916,6 +69373,41 @@ Client notes (${notes.length})`));
|
|
|
68916
69373
|
console.log(chalk21.gray('\nThese are PROPOSALS. Apply with `parity plan set-reference` / `set-status`, then confirm with `parity plan notes --page <path> --post "<what you did>"`.\n'));
|
|
68917
69374
|
return 0;
|
|
68918
69375
|
}
|
|
69376
|
+
var PROVENANCES = ["library", "built"];
|
|
69377
|
+
function planSetProvenanceCommand(dir, name, provenance) {
|
|
69378
|
+
if (!PROVENANCES.includes(provenance)) {
|
|
69379
|
+
console.error(chalk21.red(`Invalid provenance "${provenance}". Use one of: ${PROVENANCES.join(", ")}`));
|
|
69380
|
+
return 1;
|
|
69381
|
+
}
|
|
69382
|
+
const plan = loadPlan(dir);
|
|
69383
|
+
if (!plan) {
|
|
69384
|
+
console.error(chalk21.red(`No migration-plan.json found in ${dir}`));
|
|
69385
|
+
return 1;
|
|
69386
|
+
}
|
|
69387
|
+
const component = setComponentProvenance(plan, name, provenance);
|
|
69388
|
+
if (!component) {
|
|
69389
|
+
console.error(chalk21.red(`No component matching "${name}" in the plan`));
|
|
69390
|
+
return 1;
|
|
69391
|
+
}
|
|
69392
|
+
savePlan(dir, plan);
|
|
69393
|
+
console.log(`${chalk21.green("✓")} ${component.name} → ${provenance}`);
|
|
69394
|
+
return 0;
|
|
69395
|
+
}
|
|
69396
|
+
function planTouchCommand(dir, page, opts) {
|
|
69397
|
+
const plan = loadPlan(dir);
|
|
69398
|
+
if (!plan) {
|
|
69399
|
+
console.error(chalk21.red(`No migration-plan.json found in ${dir}`));
|
|
69400
|
+
return 1;
|
|
69401
|
+
}
|
|
69402
|
+
const count = recordTouch(plan, page);
|
|
69403
|
+
savePlan(dir, plan);
|
|
69404
|
+
if (opts.json) {
|
|
69405
|
+
console.log(JSON.stringify({ page, touches: count, total: totalTouches(plan) }));
|
|
69406
|
+
} else {
|
|
69407
|
+
console.log(`${chalk21.green("✓")} ${page} → ${count} human touch(es); ${totalTouches(plan)} in this migration`);
|
|
69408
|
+
}
|
|
69409
|
+
return 0;
|
|
69410
|
+
}
|
|
68919
69411
|
|
|
68920
69412
|
// src/commands/pr.ts
|
|
68921
69413
|
import { existsSync as existsSync25, readFileSync as readFileSync30, writeFileSync as writeFileSync27 } from "node:fs";
|
|
@@ -68928,6 +69420,57 @@ import { join as join36 } from "node:path";
|
|
|
68928
69420
|
import chalk23 from "chalk";
|
|
68929
69421
|
import ora8 from "ora";
|
|
68930
69422
|
|
|
69423
|
+
// src/diff/score-band.ts
|
|
69424
|
+
var uniq = (xs) => [...new Set(xs)];
|
|
69425
|
+
function computeScoreBand(current, priors, opts = {}) {
|
|
69426
|
+
const threshold = opts.showThreshold ?? 3;
|
|
69427
|
+
const scores = [current.verdict.score, ...priors.map((p) => p.score)];
|
|
69428
|
+
const spread = Math.round((Math.max(...scores) - Math.min(...scores)) * 100) / 100;
|
|
69429
|
+
const byName = new Map;
|
|
69430
|
+
for (const c of current.checks)
|
|
69431
|
+
byName.set(c.name, [c.status]);
|
|
69432
|
+
for (const p of priors) {
|
|
69433
|
+
for (const c of p.checks) {
|
|
69434
|
+
const seen = byName.get(c.name);
|
|
69435
|
+
if (seen)
|
|
69436
|
+
seen.push(c.status);
|
|
69437
|
+
}
|
|
69438
|
+
}
|
|
69439
|
+
const flipping = [];
|
|
69440
|
+
for (const [name, statuses] of byName) {
|
|
69441
|
+
if (statuses.length !== priors.length + 1)
|
|
69442
|
+
continue;
|
|
69443
|
+
const distinct = uniq(statuses);
|
|
69444
|
+
if (distinct.length > 1)
|
|
69445
|
+
flipping.push({ name, statuses: distinct.sort() });
|
|
69446
|
+
}
|
|
69447
|
+
flipping.sort((a, b) => a.name.localeCompare(b.name));
|
|
69448
|
+
return {
|
|
69449
|
+
scores,
|
|
69450
|
+
spread,
|
|
69451
|
+
priorRuns: priors.length,
|
|
69452
|
+
flipping,
|
|
69453
|
+
worthShowing: priors.length > 0 && (spread >= threshold || flipping.length > 0)
|
|
69454
|
+
};
|
|
69455
|
+
}
|
|
69456
|
+
function formatScoreBand(band) {
|
|
69457
|
+
if (!band.worthShowing)
|
|
69458
|
+
return null;
|
|
69459
|
+
const lo = Math.min(...band.scores);
|
|
69460
|
+
const hi = Math.max(...band.scores);
|
|
69461
|
+
const n = band.priorRuns + 1;
|
|
69462
|
+
const range = `last ${n} comparable runs: ${lo}–${hi} (spread ${band.spread})`;
|
|
69463
|
+
if (band.flipping.length === 0)
|
|
69464
|
+
return range;
|
|
69465
|
+
const names = band.flipping.map((f) => `${f.name} (${f.statuses.join("/")})`).join(", ");
|
|
69466
|
+
return `${range} — ${band.flipping.length} check(s) reported differently across them: ${names}`;
|
|
69467
|
+
}
|
|
69468
|
+
function scoreBandCaveat(band) {
|
|
69469
|
+
if (band.flipping.length === 0)
|
|
69470
|
+
return null;
|
|
69471
|
+
return `a check that reports differently across runs contributes points that do not track the code — read this score as ±${Math.max(band.spread, 1)} until it is stable (\`parity variance\` on two runs of unchanged code isolates it)`;
|
|
69472
|
+
}
|
|
69473
|
+
|
|
68931
69474
|
// src/engine/interactive-module-prompt.ts
|
|
68932
69475
|
import { createInterface as createInterface2 } from "node:readline";
|
|
68933
69476
|
var ALL_MODULE_NAMES2 = Object.keys(MODULES);
|
|
@@ -69890,6 +70433,15 @@ function evaluateFailOnGate(allIssues, failOn, verdictStatus) {
|
|
|
69890
70433
|
✖ ${blocking.length} issue(s) bloqueante(s) [${failOn.join(", ")}] — exit 1`
|
|
69891
70434
|
};
|
|
69892
70435
|
}
|
|
70436
|
+
var SCORE_BAND_RUNS = 4;
|
|
70437
|
+
function readRunChecks(reportPath) {
|
|
70438
|
+
try {
|
|
70439
|
+
const raw = JSON.parse(readFileSync29(reportPath, "utf8"));
|
|
70440
|
+
return (raw.checks ?? []).filter((c) => typeof c.name === "string" && typeof c.status === "string").map((c) => ({ name: c.name, status: c.status }));
|
|
70441
|
+
} catch {
|
|
70442
|
+
return [];
|
|
70443
|
+
}
|
|
70444
|
+
}
|
|
69893
70445
|
async function runCommand(rawOpts) {
|
|
69894
70446
|
if (!rawOpts.prod) {
|
|
69895
70447
|
const target = rawOpts.cand ?? "<url>";
|
|
@@ -70583,6 +71135,17 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
70583
71135
|
modulesRun: verdict.modulesRun
|
|
70584
71136
|
});
|
|
70585
71137
|
const previousRun = prevRun ? { ...prevRun, scoreDelta: verdict.score - prevRun.score } : undefined;
|
|
71138
|
+
const bandRuns = findComparableRuns(opts.output, {
|
|
71139
|
+
prodUrl: opts.prod,
|
|
71140
|
+
candUrl: opts.cand,
|
|
71141
|
+
excludeRunId: runId,
|
|
71142
|
+
scoreVersion: verdict.scoreVersion,
|
|
71143
|
+
modulesRun: verdict.modulesRun
|
|
71144
|
+
}, SCORE_BAND_RUNS);
|
|
71145
|
+
const scoreBand = computeScoreBand({ verdict, checks }, bandRuns.map((r) => ({
|
|
71146
|
+
score: r.score,
|
|
71147
|
+
checks: readRunChecks(r.reportPath)
|
|
71148
|
+
})));
|
|
70586
71149
|
let baselineSection;
|
|
70587
71150
|
if (opts.baseline) {
|
|
70588
71151
|
try {
|
|
@@ -70620,6 +71183,7 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
70620
71183
|
durationMs: Date.now() - startedAt,
|
|
70621
71184
|
verdict,
|
|
70622
71185
|
previousRun,
|
|
71186
|
+
scoreBand,
|
|
70623
71187
|
topIssues,
|
|
70624
71188
|
issues: allIssues,
|
|
70625
71189
|
checks,
|
|
@@ -70900,6 +71464,14 @@ function printSummary7(run, htmlPath, meta) {
|
|
|
70900
71464
|
}
|
|
70901
71465
|
console.log(` checks: ${chalk23.green(verdict.checksPassed)} pass · ${chalk23.red(verdict.checksFailed)} fail · ${chalk23.dim(`${verdict.checksSkipped} skipped`)}`);
|
|
70902
71466
|
console.log(` issues: ${chalk23.red(verdict.critical)} critical · ${chalk23.yellow(verdict.high)} high · ${verdict.medium} medium · ${chalk23.dim(`${verdict.low} low`)}`);
|
|
71467
|
+
const band = run.scoreBand;
|
|
71468
|
+
const bandLine = band ? formatScoreBand(band) : null;
|
|
71469
|
+
if (band && bandLine) {
|
|
71470
|
+
console.log(` ${chalk23.dim(bandLine)}`);
|
|
71471
|
+
const caveat = scoreBandCaveat(band);
|
|
71472
|
+
if (caveat)
|
|
71473
|
+
console.log(` ${chalk23.yellow("⚠")} ${caveat}`);
|
|
71474
|
+
}
|
|
70903
71475
|
for (const c of run.caveats ?? []) {
|
|
70904
71476
|
const mark = c.level === "warn" ? chalk23.yellow("⚠") : chalk23.dim("ℹ");
|
|
70905
71477
|
console.log(` ${mark} ${c.summary}`);
|
|
@@ -71731,6 +72303,7 @@ import chalk27 from "chalk";
|
|
|
71731
72303
|
|
|
71732
72304
|
// src/diff/motion.ts
|
|
71733
72305
|
var WEIGHT = {
|
|
72306
|
+
"moved-to-descendant": 45,
|
|
71734
72307
|
"missing-transition": 100,
|
|
71735
72308
|
"missing-animation": 100,
|
|
71736
72309
|
"extra-transition": 70,
|
|
@@ -71743,8 +72316,15 @@ var WEIGHT = {
|
|
|
71743
72316
|
easing: 15,
|
|
71744
72317
|
delay: 10
|
|
71745
72318
|
};
|
|
71746
|
-
function finding(node, kind, detail) {
|
|
71747
|
-
return {
|
|
72319
|
+
function finding(node, kind, detail, candKey) {
|
|
72320
|
+
return {
|
|
72321
|
+
key: node.key,
|
|
72322
|
+
...candKey && candKey !== node.key ? { candKey } : {},
|
|
72323
|
+
label: node.label,
|
|
72324
|
+
kind,
|
|
72325
|
+
detail,
|
|
72326
|
+
weight: WEIGHT[kind]
|
|
72327
|
+
};
|
|
71748
72328
|
}
|
|
71749
72329
|
function sameSet(a, b) {
|
|
71750
72330
|
if (a.length !== b.length)
|
|
@@ -71754,35 +72334,53 @@ function sameSet(a, b) {
|
|
|
71754
72334
|
return sa.every((v, i) => v === sb[i]);
|
|
71755
72335
|
}
|
|
71756
72336
|
var list = (v) => v.length ? v.join(", ") : "none";
|
|
71757
|
-
function
|
|
72337
|
+
function descendantWithTransition(nodes, ancestorKey, props) {
|
|
72338
|
+
const wanted = new Set(props);
|
|
72339
|
+
for (const n of nodes) {
|
|
72340
|
+
if (!n.key.startsWith(`${ancestorKey}>`))
|
|
72341
|
+
continue;
|
|
72342
|
+
if (!n.transition.durationsMs.some((d) => d > 0))
|
|
72343
|
+
continue;
|
|
72344
|
+
if (n.transition.properties.some((x) => wanted.has(x) || x === "all"))
|
|
72345
|
+
return n;
|
|
72346
|
+
}
|
|
72347
|
+
return null;
|
|
72348
|
+
}
|
|
72349
|
+
function diffTransitions(p, c, candNodes) {
|
|
71758
72350
|
const out = [];
|
|
72351
|
+
const at = c.key;
|
|
71759
72352
|
const pOn = p.transition.properties.length > 0 && p.transition.durationsMs.some((d) => d > 0);
|
|
71760
72353
|
const cOn = c.transition.properties.length > 0 && c.transition.durationsMs.some((d) => d > 0);
|
|
71761
72354
|
if (pOn && !cOn) {
|
|
71762
|
-
|
|
72355
|
+
const inner = descendantWithTransition(candNodes, c.key, p.transition.properties);
|
|
72356
|
+
if (inner) {
|
|
72357
|
+
out.push(finding(p, "moved-to-descendant", `prod transitions ${list(p.transition.properties)} over ${Math.max(...p.transition.durationsMs)}ms on this node; cand declares it on a DESCENDANT instead (${inner.key}: ${list(inner.transition.properties)} over ${Math.max(...inner.transition.durationsMs)}ms). The effect exists — the node carrying it differs, which is a structural difference, not a lost transition.`, at));
|
|
72358
|
+
return out;
|
|
72359
|
+
}
|
|
72360
|
+
out.push(finding(p, "missing-transition", `prod transitions ${list(p.transition.properties)} over ${Math.max(...p.transition.durationsMs)}ms; cand's node ${c.key} has no transition, and no descendant of it declares one either (the change is instant)`, at));
|
|
71763
72361
|
return out;
|
|
71764
72362
|
}
|
|
71765
72363
|
if (!pOn && cOn) {
|
|
71766
|
-
out.push(finding(p, "extra-transition", `cand transitions ${list(c.transition.properties)}; prod does not (the migration added motion)
|
|
72364
|
+
out.push(finding(p, "extra-transition", `cand transitions ${list(c.transition.properties)}; prod does not (the migration added motion)`, at));
|
|
71767
72365
|
return out;
|
|
71768
72366
|
}
|
|
71769
72367
|
if (!pOn && !cOn)
|
|
71770
72368
|
return out;
|
|
71771
72369
|
if (!sameSet(p.transition.properties, c.transition.properties)) {
|
|
71772
|
-
out.push(finding(p, "property-set", `transitioned properties differ: prod [${list(p.transition.properties)}] vs cand [${list(c.transition.properties)}]
|
|
72370
|
+
out.push(finding(p, "property-set", `transitioned properties differ: prod [${list(p.transition.properties)}] vs cand [${list(c.transition.properties)}]`, at));
|
|
71773
72371
|
}
|
|
71774
72372
|
const pd = Math.max(...p.transition.durationsMs);
|
|
71775
72373
|
const cd = Math.max(...c.transition.durationsMs);
|
|
71776
72374
|
if (pd !== cd) {
|
|
71777
|
-
out.push(finding(p, "duration", `transition duration ${pd}ms → ${cd}ms
|
|
72375
|
+
out.push(finding(p, "duration", `transition duration ${pd}ms → ${cd}ms`, at));
|
|
71778
72376
|
}
|
|
71779
72377
|
if (!sameSet(p.transition.easings, c.transition.easings)) {
|
|
71780
|
-
out.push(finding(p, "easing", `transition easing [${list(p.transition.easings)}] → [${list(c.transition.easings)}]
|
|
72378
|
+
out.push(finding(p, "easing", `transition easing [${list(p.transition.easings)}] → [${list(c.transition.easings)}]`, at));
|
|
71781
72379
|
}
|
|
71782
72380
|
const pdel = Math.max(0, ...p.transition.delaysMs);
|
|
71783
72381
|
const cdel = Math.max(0, ...c.transition.delaysMs);
|
|
71784
72382
|
if (pdel !== cdel) {
|
|
71785
|
-
out.push(finding(p, "delay", `transition delay ${pdel}ms → ${cdel}ms
|
|
72383
|
+
out.push(finding(p, "delay", `transition delay ${pdel}ms → ${cdel}ms`, at));
|
|
71786
72384
|
}
|
|
71787
72385
|
return out;
|
|
71788
72386
|
}
|
|
@@ -71791,14 +72389,15 @@ function keyframesFingerprint(k) {
|
|
|
71791
72389
|
}
|
|
71792
72390
|
function diffAnimations(p, c) {
|
|
71793
72391
|
const out = [];
|
|
72392
|
+
const at = c.key;
|
|
71794
72393
|
const pNames = p.animation.names.filter((n) => n && n !== "none");
|
|
71795
72394
|
const cNames = c.animation.names.filter((n) => n && n !== "none");
|
|
71796
72395
|
if (pNames.length > 0 && cNames.length === 0) {
|
|
71797
|
-
out.push(finding(p, "missing-animation", `prod animates [${list(pNames)}]; cand has no animation
|
|
72396
|
+
out.push(finding(p, "missing-animation", `prod animates [${list(pNames)}]; cand has no animation`, at));
|
|
71798
72397
|
return out;
|
|
71799
72398
|
}
|
|
71800
72399
|
if (pNames.length === 0 && cNames.length > 0) {
|
|
71801
|
-
out.push(finding(p, "extra-animation", `cand animates [${list(cNames)}]; prod does not
|
|
72400
|
+
out.push(finding(p, "extra-animation", `cand animates [${list(cNames)}]; prod does not`, at));
|
|
71802
72401
|
return out;
|
|
71803
72402
|
}
|
|
71804
72403
|
if (pNames.length === 0)
|
|
@@ -71806,7 +72405,7 @@ function diffAnimations(p, c) {
|
|
|
71806
72405
|
const pd = Math.max(...p.animation.durationsMs);
|
|
71807
72406
|
const cd = Math.max(...c.animation.durationsMs);
|
|
71808
72407
|
if (pd !== cd)
|
|
71809
|
-
out.push(finding(p, "duration", `animation duration ${pd}ms → ${cd}ms
|
|
72408
|
+
out.push(finding(p, "duration", `animation duration ${pd}ms → ${cd}ms`, at));
|
|
71810
72409
|
for (const [i, name] of pNames.entries()) {
|
|
71811
72410
|
const pk = p.keyframes[name];
|
|
71812
72411
|
const cname = cNames[i];
|
|
@@ -71814,11 +72413,11 @@ function diffAnimations(p, c) {
|
|
|
71814
72413
|
if (!pk)
|
|
71815
72414
|
continue;
|
|
71816
72415
|
if (!ck) {
|
|
71817
|
-
out.push(finding(p, "keyframes", `prod's @keyframes ${name} has no counterpart on the cand side
|
|
72416
|
+
out.push(finding(p, "keyframes", `prod's @keyframes ${name} has no counterpart on the cand side`, at));
|
|
71818
72417
|
continue;
|
|
71819
72418
|
}
|
|
71820
72419
|
if (keyframesFingerprint(pk) !== keyframesFingerprint(ck)) {
|
|
71821
|
-
out.push(finding(p, "keyframes", `@keyframes differ (prod ${name}: ${pk.steps.length} steps, cand ${cname}: ${ck.steps.length} steps)
|
|
72420
|
+
out.push(finding(p, "keyframes", `@keyframes differ (prod ${name}: ${pk.steps.length} steps, cand ${cname}: ${ck.steps.length} steps)`, at));
|
|
71822
72421
|
}
|
|
71823
72422
|
}
|
|
71824
72423
|
return out;
|
|
@@ -71829,7 +72428,8 @@ function diffMotion(prod, cand, opts = {}) {
|
|
|
71829
72428
|
for (const n of cand.nodes) {
|
|
71830
72429
|
if (!n.label)
|
|
71831
72430
|
continue;
|
|
71832
|
-
|
|
72431
|
+
const k = canonicalLabel(opts.aliases, n.label);
|
|
72432
|
+
labelSeen.set(k, labelSeen.has(k) ? null : n);
|
|
71833
72433
|
}
|
|
71834
72434
|
const byLabel = new Map;
|
|
71835
72435
|
for (const [k, v] of labelSeen)
|
|
@@ -71839,14 +72439,14 @@ function diffMotion(prod, cand, opts = {}) {
|
|
|
71839
72439
|
const used = new Set;
|
|
71840
72440
|
let matched = 0;
|
|
71841
72441
|
for (const p of prod.nodes) {
|
|
71842
|
-
const c =
|
|
72442
|
+
const c = (p.label ? byLabel.get(canonicalLabel(opts.aliases, p.label)) : undefined) ?? byKey.get(p.key);
|
|
71843
72443
|
if (!c || used.has(c)) {
|
|
71844
72444
|
findings.push(finding(p, "only-in-prod", `${p.tag}${p.label ? ` (${p.label})` : ""} has no counterpart`));
|
|
71845
72445
|
continue;
|
|
71846
72446
|
}
|
|
71847
72447
|
used.add(c);
|
|
71848
72448
|
matched++;
|
|
71849
|
-
findings.push(...diffTransitions(p, c), ...diffAnimations(p, c));
|
|
72449
|
+
findings.push(...diffTransitions(p, c, cand.nodes), ...diffAnimations(p, c));
|
|
71850
72450
|
}
|
|
71851
72451
|
findings.sort((a, b) => b.weight - a.weight || a.key.localeCompare(b.key) || a.kind.localeCompare(b.kind));
|
|
71852
72452
|
return {
|
|
@@ -71858,25 +72458,63 @@ function diffMotion(prod, cand, opts = {}) {
|
|
|
71858
72458
|
function isMotionClean(diff) {
|
|
71859
72459
|
return diff.findings.length === 0;
|
|
71860
72460
|
}
|
|
72461
|
+
function groupMotionFindings(findings) {
|
|
72462
|
+
const groups = new Map;
|
|
72463
|
+
for (const f of findings) {
|
|
72464
|
+
const id = `${f.kind}\x00${f.detail}`;
|
|
72465
|
+
const g = groups.get(id);
|
|
72466
|
+
if (g)
|
|
72467
|
+
g.keys.push(f.key);
|
|
72468
|
+
else
|
|
72469
|
+
groups.set(id, {
|
|
72470
|
+
kind: f.kind,
|
|
72471
|
+
detail: f.detail,
|
|
72472
|
+
keys: [f.key],
|
|
72473
|
+
...f.candKey ? { candKey: f.candKey } : {},
|
|
72474
|
+
weight: f.weight
|
|
72475
|
+
});
|
|
72476
|
+
}
|
|
72477
|
+
return [...groups.values()].sort((a, b) => b.weight - a.weight || b.keys.length - a.keys.length || a.keys[0].localeCompare(b.keys[0]));
|
|
72478
|
+
}
|
|
71861
72479
|
function formatMotionDiff(diff, opts = {}) {
|
|
71862
72480
|
if (isMotionClean(diff)) {
|
|
71863
|
-
|
|
72481
|
+
const caveat = diff.truncated ? " — TRUNCATED" : "";
|
|
72482
|
+
return diff.matched === 0 ? `motion: nothing to compare — no interactive element paired inside the selector${caveat}` : `motion: clean (${diff.matched} interactive elements matched)${caveat}`;
|
|
71864
72483
|
}
|
|
71865
72484
|
const limit = opts.limit ?? 30;
|
|
71866
|
-
const
|
|
71867
|
-
const
|
|
71868
|
-
const
|
|
71869
|
-
|
|
71870
|
-
|
|
72485
|
+
const groups = groupMotionFindings(diff.findings);
|
|
72486
|
+
const structural = groups.filter((g) => g.kind === "only-in-prod" || g.kind === "only-in-cand");
|
|
72487
|
+
const real = groups.filter((g) => g.kind !== "only-in-prod" && g.kind !== "only-in-cand");
|
|
72488
|
+
const shown = real.slice(0, limit);
|
|
72489
|
+
const lines = [];
|
|
72490
|
+
for (const g of shown) {
|
|
72491
|
+
const head = g.keys.length > 1 ? `${g.keys[0]} (+${g.keys.length - 1} more)` : g.keys[0];
|
|
72492
|
+
lines.push(`${head} ${g.kind} ${g.detail}`);
|
|
72493
|
+
if (g.candKey)
|
|
72494
|
+
lines.push(` cand node: ${g.candKey}`);
|
|
72495
|
+
if (g.keys.length > 1) {
|
|
72496
|
+
for (const k of g.keys.slice(1))
|
|
72497
|
+
lines.push(` also: ${k}`);
|
|
72498
|
+
}
|
|
72499
|
+
}
|
|
72500
|
+
if (real.length > shown.length)
|
|
72501
|
+
lines.push(`… ${real.length - shown.length} more`);
|
|
72502
|
+
if (real.length === 0)
|
|
72503
|
+
lines.push("no motion differences on paired elements");
|
|
72504
|
+
const structuralCount = structural.reduce((n, g) => n + g.keys.length, 0);
|
|
72505
|
+
if (structuralCount > 0) {
|
|
72506
|
+
lines.push(`${structuralCount} element(s) had no counterpart on the other side — structural, not motion; see the box-tree diff`);
|
|
72507
|
+
}
|
|
72508
|
+
if (diff.truncated) {
|
|
72509
|
+
lines.push("TRUNCATED — element cap hit; absence of a finding is not proof, and a declaration reported on N elements may sit on more");
|
|
71871
72510
|
}
|
|
71872
|
-
if (diff.truncated)
|
|
71873
|
-
lines.push("TRUNCATED — element cap hit; absence of a finding is not proof");
|
|
71874
72511
|
return lines.join(`
|
|
71875
72512
|
`);
|
|
71876
72513
|
}
|
|
71877
72514
|
|
|
71878
72515
|
// src/engine/motion.ts
|
|
71879
72516
|
var LABEL_ATTRS2 = ["data-section", "data-testid", "data-fs-section", "data-manifest-key", "id"];
|
|
72517
|
+
var GENERATED_ID2 = /^(?::[rR][0-9a-zA-Z]*:|_[rR]_[0-9a-zA-Z_]*_)$/;
|
|
71880
72518
|
async function readMotion(page, selector, opts = {}) {
|
|
71881
72519
|
const maxNodes = opts.maxNodes ?? 80;
|
|
71882
72520
|
const maxDepth = opts.maxDepth ?? 12;
|
|
@@ -71891,7 +72529,7 @@ async function readMotion(page, selector, opts = {}) {
|
|
|
71891
72529
|
}
|
|
71892
72530
|
let got;
|
|
71893
72531
|
try {
|
|
71894
|
-
got = await page.evaluate(({ sel, maxNodes, maxDepth, labelAttrs }) => {
|
|
72532
|
+
got = await page.evaluate(({ sel, maxNodes, maxDepth, labelAttrs, generatedIdPattern }) => {
|
|
71895
72533
|
try {
|
|
71896
72534
|
const root = document.querySelector(sel);
|
|
71897
72535
|
if (!root || !(root instanceof HTMLElement)) {
|
|
@@ -71936,11 +72574,15 @@ async function readMotion(page, selector, opts = {}) {
|
|
|
71936
72574
|
collect(sheet.cssRules);
|
|
71937
72575
|
} catch {}
|
|
71938
72576
|
}
|
|
72577
|
+
const generatedId = new RegExp(generatedIdPattern);
|
|
71939
72578
|
const labelOf = (el) => {
|
|
71940
72579
|
for (const a of labelAttrs) {
|
|
71941
72580
|
const v = el.getAttribute(a);
|
|
71942
|
-
if (v)
|
|
71943
|
-
|
|
72581
|
+
if (!v)
|
|
72582
|
+
continue;
|
|
72583
|
+
if (a === "id" && generatedId.test(v))
|
|
72584
|
+
continue;
|
|
72585
|
+
return v;
|
|
71944
72586
|
}
|
|
71945
72587
|
return null;
|
|
71946
72588
|
};
|
|
@@ -72006,7 +72648,13 @@ async function readMotion(page, selector, opts = {}) {
|
|
|
72006
72648
|
reason: `leitura de motion falhou em '${sel}': ${err.message ?? "unknown"}`
|
|
72007
72649
|
};
|
|
72008
72650
|
}
|
|
72009
|
-
}, {
|
|
72651
|
+
}, {
|
|
72652
|
+
sel: selector,
|
|
72653
|
+
maxNodes,
|
|
72654
|
+
maxDepth,
|
|
72655
|
+
labelAttrs: LABEL_ATTRS2,
|
|
72656
|
+
generatedIdPattern: GENERATED_ID2.source
|
|
72657
|
+
});
|
|
72010
72658
|
} catch (err) {
|
|
72011
72659
|
return {
|
|
72012
72660
|
found: false,
|
|
@@ -72052,6 +72700,8 @@ async function gatherBenchSide(browser, opts) {
|
|
|
72052
72700
|
});
|
|
72053
72701
|
if (opts.waitMs > 0)
|
|
72054
72702
|
await page.waitForTimeout(opts.waitMs);
|
|
72703
|
+
await reloadIfOptionalFonts(page, opts.waitMs);
|
|
72704
|
+
side.settle = await waitForLayoutStable(page);
|
|
72055
72705
|
side.boxNodes = await readBoxTree(page, opts.selector);
|
|
72056
72706
|
side.motion = await readMotion(page, opts.selector);
|
|
72057
72707
|
if (opts.screenshotPath && side.boxNodes.found) {
|
|
@@ -72103,6 +72753,9 @@ async function benchCommand(opts) {
|
|
|
72103
72753
|
mkdirSync18(opts.outDir, { recursive: true });
|
|
72104
72754
|
const slug = opts.component.replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
|
|
72105
72755
|
const prefix = `bench-${slug}-${viewport}`;
|
|
72756
|
+
const { aliases, note: aliasNote } = resolveAliases(opts.planDir);
|
|
72757
|
+
if (aliasNote)
|
|
72758
|
+
console.log(chalk27.dim(` ${aliasNote}`));
|
|
72106
72759
|
const browser = await launchBrowser({ headless: true });
|
|
72107
72760
|
try {
|
|
72108
72761
|
const [prodSide, candSide] = await Promise.all([
|
|
@@ -72131,10 +72784,12 @@ async function benchCommand(opts) {
|
|
|
72131
72784
|
return 2;
|
|
72132
72785
|
}
|
|
72133
72786
|
const geometry = diffBoxTrees(prodSide.boxNodes.nodes, candSide.boxNodes.nodes, {
|
|
72134
|
-
truncated: prodSide.boxNodes.truncated || candSide.boxNodes.truncated
|
|
72787
|
+
truncated: prodSide.boxNodes.truncated || candSide.boxNodes.truncated,
|
|
72788
|
+
aliases
|
|
72135
72789
|
});
|
|
72136
|
-
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion) : null;
|
|
72790
|
+
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion, { aliases }) : null;
|
|
72137
72791
|
const clean = isGeometryClean(geometry) && (motion?.findings.length ?? 0) === 0;
|
|
72792
|
+
const inconclusive = isBoxTreeInconclusive(geometry);
|
|
72138
72793
|
const result = {
|
|
72139
72794
|
component: opts.component,
|
|
72140
72795
|
viewport,
|
|
@@ -72142,9 +72797,11 @@ async function benchCommand(opts) {
|
|
|
72142
72797
|
candUrl,
|
|
72143
72798
|
propsFile: opts.props ?? null,
|
|
72144
72799
|
clean,
|
|
72800
|
+
inconclusive,
|
|
72145
72801
|
geometry,
|
|
72146
72802
|
motion,
|
|
72147
|
-
screenshots: { prod: prodSide.screenshotPath ?? null, cand: candSide.screenshotPath ?? null }
|
|
72803
|
+
screenshots: { prod: prodSide.screenshotPath ?? null, cand: candSide.screenshotPath ?? null },
|
|
72804
|
+
settle: { prod: prodSide.settle ?? null, cand: candSide.settle ?? null }
|
|
72148
72805
|
};
|
|
72149
72806
|
const resultPath = resolve8(opts.outDir, `${prefix}.json`);
|
|
72150
72807
|
writeFileSync30(resultPath, `${JSON.stringify(result, null, 2)}
|
|
@@ -72160,6 +72817,14 @@ async function benchCommand(opts) {
|
|
|
72160
72817
|
for (const line of formatBoxTreeDiff(geometry).split(`
|
|
72161
72818
|
`))
|
|
72162
72819
|
console.log(` ${line}`);
|
|
72820
|
+
for (const [name, data] of [
|
|
72821
|
+
["prod", prodSide],
|
|
72822
|
+
["cand", candSide]
|
|
72823
|
+
]) {
|
|
72824
|
+
const caveat = data.settle && formatSettleCaveat(name, data.settle);
|
|
72825
|
+
if (caveat)
|
|
72826
|
+
console.log(chalk27.yellow(` ${caveat}`));
|
|
72827
|
+
}
|
|
72163
72828
|
if (motion) {
|
|
72164
72829
|
console.log("");
|
|
72165
72830
|
for (const line of formatMotionDiff(motion).split(`
|
|
@@ -72177,10 +72842,1375 @@ async function benchCommand(opts) {
|
|
|
72177
72842
|
}
|
|
72178
72843
|
}
|
|
72179
72844
|
|
|
72180
|
-
// src/commands/
|
|
72845
|
+
// src/commands/locate.ts
|
|
72181
72846
|
import chalk28 from "chalk";
|
|
72847
|
+
var hitOf = (n, nodes) => ({
|
|
72848
|
+
key: n.key,
|
|
72849
|
+
label: n.label,
|
|
72850
|
+
tag: n.tag,
|
|
72851
|
+
rect: n.rect,
|
|
72852
|
+
fontSize: n.styles["font-size"] ?? "?",
|
|
72853
|
+
fontWeight: n.styles["font-weight"] ?? "?",
|
|
72854
|
+
textAlign: n.styles["text-align"] ?? "?",
|
|
72855
|
+
contributesBox: !addsNoBoxOfItsOwn(n, nodes)
|
|
72856
|
+
});
|
|
72857
|
+
var isZeroPx = (v) => !v || v === "0px";
|
|
72858
|
+
function addsNoBoxOfItsOwn(n, nodes) {
|
|
72859
|
+
const pads = ["padding-top", "padding-right", "padding-bottom", "padding-left"];
|
|
72860
|
+
if (!pads.every((k) => isZeroPx(n.styles[k])))
|
|
72861
|
+
return false;
|
|
72862
|
+
return nodes.some((o) => o !== n && o.key.startsWith(`${n.key}>`) && Math.abs(o.rect.height - n.rect.height) <= 1);
|
|
72863
|
+
}
|
|
72864
|
+
function pairingNotes(prod, cand) {
|
|
72865
|
+
const notes = [];
|
|
72866
|
+
if (prod.contributesBox !== cand.contributesBox) {
|
|
72867
|
+
const bare = prod.contributesBox ? "cand" : "prod";
|
|
72868
|
+
const other = bare === "prod" ? "cand" : "prod";
|
|
72869
|
+
notes.push(`${bare}'s match adds no box of its own (no padding, and something inside it exactly as tall) while ${other}'s does — the label may have collapsed one level too far on that side, and the difference below may be ${other}'s padding. Re-run against the outer element's own id to check.`);
|
|
72870
|
+
}
|
|
72871
|
+
for (const [name, hit] of [
|
|
72872
|
+
["prod", prod],
|
|
72873
|
+
["cand", cand]
|
|
72874
|
+
]) {
|
|
72875
|
+
if (isImplausiblyShort(hit)) {
|
|
72876
|
+
notes.push(`${name}'s match is ${hit.rect.height}px tall with a ${hit.fontSize} font — that is an inline box reporting its line box, not the control the label belongs to. The label likely descended into an inner element on that side.`);
|
|
72877
|
+
}
|
|
72878
|
+
}
|
|
72879
|
+
if (prod.tag !== cand.tag && Math.abs(prod.rect.width - cand.rect.width) > 1 && Math.abs(prod.rect.height - cand.rect.height) > 1) {
|
|
72880
|
+
notes.push(`tag, width and height all differ (${prod.tag} ${prod.rect.width}×${prod.rect.height} vs ${cand.tag} ${cand.rect.width}×${cand.rect.height}) — two elements that are genuinely the same one rarely disagree on all three at once.`);
|
|
72881
|
+
}
|
|
72882
|
+
return notes;
|
|
72883
|
+
}
|
|
72884
|
+
function isImplausiblyShort(hit) {
|
|
72885
|
+
const size = Number.parseFloat(hit.fontSize);
|
|
72886
|
+
if (!Number.isFinite(size) || size <= 0)
|
|
72887
|
+
return false;
|
|
72888
|
+
return hit.rect.height > 0 && hit.rect.height < size * 0.9;
|
|
72889
|
+
}
|
|
72890
|
+
function findByLabel(nodes, label, aliases) {
|
|
72891
|
+
const wanted = canonicalLabel(aliases, label).toLowerCase();
|
|
72892
|
+
const byAttr = nodes.filter((n) => n.label && canonicalLabel(aliases, n.label).toLowerCase() === wanted);
|
|
72893
|
+
const pool = byAttr.length > 0 ? byAttr : nodes.filter((n) => matchesText(n, label));
|
|
72894
|
+
return pool.filter((n) => !pool.some((o) => o !== n && o.key.startsWith(`${n.key}>`)));
|
|
72895
|
+
}
|
|
72896
|
+
function matchesText(n, label) {
|
|
72897
|
+
const t = n.text?.toLowerCase();
|
|
72898
|
+
return Boolean(t?.startsWith(label.trim().toLowerCase()));
|
|
72899
|
+
}
|
|
72900
|
+
function answer(nodes, label, aliases) {
|
|
72901
|
+
const hits = findByLabel(nodes, label, aliases);
|
|
72902
|
+
const only = hits.length === 1 ? hits[0] : undefined;
|
|
72903
|
+
if (only)
|
|
72904
|
+
return { found: true, hit: hitOf(only, nodes) };
|
|
72905
|
+
if (hits.length === 0)
|
|
72906
|
+
return { found: false, reason: "no element carries this label" };
|
|
72907
|
+
return {
|
|
72908
|
+
found: false,
|
|
72909
|
+
reason: `${hits.length} elements carry this label — cannot tell which`,
|
|
72910
|
+
candidates: hits.slice(0, 4).map((n) => n.key)
|
|
72911
|
+
};
|
|
72912
|
+
}
|
|
72913
|
+
async function readSide(browser, opts) {
|
|
72914
|
+
const ctx = await newContext(browser, { viewport: opts.viewport });
|
|
72915
|
+
const page = await ctx.newPage();
|
|
72916
|
+
try {
|
|
72917
|
+
const res = await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 }).catch((err) => err);
|
|
72918
|
+
if (res instanceof Error)
|
|
72919
|
+
return { nodes: null, error: `${opts.url} — ${res.message.split(`
|
|
72920
|
+
`)[0]}` };
|
|
72921
|
+
if (res && res.status() >= 400)
|
|
72922
|
+
return { nodes: null, error: `${opts.url} — HTTP ${res.status()}` };
|
|
72923
|
+
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
72924
|
+
return;
|
|
72925
|
+
});
|
|
72926
|
+
if (opts.waitMs > 0)
|
|
72927
|
+
await page.waitForTimeout(opts.waitMs);
|
|
72928
|
+
const warmed = await reloadIfOptionalFonts(page, opts.waitMs);
|
|
72929
|
+
await scrollFullPage(page, 15000).catch(() => {
|
|
72930
|
+
return;
|
|
72931
|
+
});
|
|
72932
|
+
const settle = await waitForLayoutStable(page);
|
|
72933
|
+
const box = await readBoxTree(page, opts.selector, { maxNodes: 6000, maxDepth: 30 });
|
|
72934
|
+
if (!box.found)
|
|
72935
|
+
return { nodes: null, error: box.error, settle, warmed };
|
|
72936
|
+
return { nodes: box.nodes, settle, warmed };
|
|
72937
|
+
} finally {
|
|
72938
|
+
await page.context().close().catch(() => {
|
|
72939
|
+
return;
|
|
72940
|
+
});
|
|
72941
|
+
}
|
|
72942
|
+
}
|
|
72943
|
+
function formatDelta(prod, cand) {
|
|
72944
|
+
const parts = [];
|
|
72945
|
+
const px = (name, a, b) => {
|
|
72946
|
+
const pa = Number.parseFloat(a);
|
|
72947
|
+
const pb = Number.parseFloat(b);
|
|
72948
|
+
if (!Number.isFinite(pa) || !Number.isFinite(pb) || pa === pb)
|
|
72949
|
+
return;
|
|
72950
|
+
const d = Math.round((pb - pa) * 100) / 100;
|
|
72951
|
+
parts.push(`${name} ${d > 0 ? "+" : ""}${d}`);
|
|
72952
|
+
};
|
|
72953
|
+
px("font-size", prod.fontSize, cand.fontSize);
|
|
72954
|
+
px("font-weight", prod.fontWeight, cand.fontWeight);
|
|
72955
|
+
if (prod.textAlign !== cand.textAlign) {
|
|
72956
|
+
parts.push(`text-align ${prod.textAlign} → ${cand.textAlign}`);
|
|
72957
|
+
}
|
|
72958
|
+
for (const k of ["x", "y", "width", "height"]) {
|
|
72959
|
+
px(k, String(prod.rect[k]), String(cand.rect[k]));
|
|
72960
|
+
}
|
|
72961
|
+
return parts.length > 0 ? parts.join(" ") : null;
|
|
72962
|
+
}
|
|
72963
|
+
function formatHit(h) {
|
|
72964
|
+
const { x, y, width, height } = h.rect;
|
|
72965
|
+
return `x${x} y${y} w${width} h${height} ${h.fontSize}/${h.fontWeight} ${h.textAlign}`;
|
|
72966
|
+
}
|
|
72967
|
+
function printResult3(r) {
|
|
72968
|
+
const side = (name, a) => {
|
|
72969
|
+
if (a.found) {
|
|
72970
|
+
console.log(` ${name.padEnd(5)} ${a.hit.tag.padEnd(8)} ${formatHit(a.hit)}`);
|
|
72971
|
+
console.log(chalk28.dim(` node: ${a.hit.key}${a.hit.label ? ` (${a.hit.label})` : ""}`));
|
|
72972
|
+
return;
|
|
72973
|
+
}
|
|
72974
|
+
console.log(chalk28.yellow(` ${name.padEnd(5)} ${a.reason}`));
|
|
72975
|
+
for (const c of a.candidates ?? [])
|
|
72976
|
+
console.log(chalk28.dim(` candidate: ${c}`));
|
|
72977
|
+
};
|
|
72978
|
+
console.log("");
|
|
72979
|
+
console.log(chalk28.bold(` ${r.label} — ${r.viewport}`));
|
|
72980
|
+
side("prod", r.prod);
|
|
72981
|
+
side("cand", r.cand);
|
|
72982
|
+
if (r.prod.found && r.cand.found) {
|
|
72983
|
+
const delta = formatDelta(r.prod.hit, r.cand.hit);
|
|
72984
|
+
console.log(` ${"diff".padEnd(5)} ${delta ?? "identical box and type"}`);
|
|
72985
|
+
for (const note of pairingNotes(r.prod.hit, r.cand.hit)) {
|
|
72986
|
+
console.log(chalk28.yellow(` note ${note}`));
|
|
72987
|
+
}
|
|
72988
|
+
}
|
|
72989
|
+
}
|
|
72990
|
+
async function locateCommand(opts) {
|
|
72991
|
+
const selector = opts.selector ?? "body";
|
|
72992
|
+
const waitMs = Number.parseInt(opts.wait, 10);
|
|
72993
|
+
if (!Number.isFinite(waitMs) || waitMs < 0) {
|
|
72994
|
+
console.error(chalk28.red(`--wait inválido: ${opts.wait}`));
|
|
72995
|
+
return 2;
|
|
72996
|
+
}
|
|
72997
|
+
if (opts.labels.length === 0) {
|
|
72998
|
+
console.error(chalk28.red("nenhum --label passado — o comando procura por label, não por seletor"));
|
|
72999
|
+
return 2;
|
|
73000
|
+
}
|
|
73001
|
+
const viewports = opts.viewports.split(",").map((v) => v.trim());
|
|
73002
|
+
const bad = viewports.find((v) => parseViewport3(v) === null);
|
|
73003
|
+
if (bad) {
|
|
73004
|
+
console.error(chalk28.red(`viewport inválido: ${bad} (mobile | tablet | desktop)`));
|
|
73005
|
+
return 2;
|
|
73006
|
+
}
|
|
73007
|
+
const { aliases, note } = resolveAliases(opts.planDir);
|
|
73008
|
+
if (note && !opts.json)
|
|
73009
|
+
console.log(chalk28.dim(` ${note}`));
|
|
73010
|
+
const results = [];
|
|
73011
|
+
const caveats = [];
|
|
73012
|
+
const browser = await launchBrowser({ headless: true });
|
|
73013
|
+
try {
|
|
73014
|
+
for (const raw of viewports) {
|
|
73015
|
+
const viewport = parseViewport3(raw);
|
|
73016
|
+
if (!viewport)
|
|
73017
|
+
continue;
|
|
73018
|
+
const [prod, cand] = await Promise.all([
|
|
73019
|
+
readSide(browser, { url: opts.prod, viewport, selector, waitMs }),
|
|
73020
|
+
readSide(browser, { url: opts.cand, viewport, selector, waitMs })
|
|
73021
|
+
]);
|
|
73022
|
+
for (const [name, side] of [
|
|
73023
|
+
["prod", prod],
|
|
73024
|
+
["cand", cand]
|
|
73025
|
+
]) {
|
|
73026
|
+
const caveat = side.settle && formatSettleCaveat(`${name} @ ${raw}`, side.settle);
|
|
73027
|
+
if (caveat)
|
|
73028
|
+
caveats.push(caveat);
|
|
73029
|
+
if (side.warmed) {
|
|
73030
|
+
caveats.push(`${name} @ ${raw}: declares font-display: optional, so the first view paints the fallback face and never swaps — measured on a second visit with the font cached`);
|
|
73031
|
+
}
|
|
73032
|
+
}
|
|
73033
|
+
for (const label of opts.labels) {
|
|
73034
|
+
results.push({
|
|
73035
|
+
label,
|
|
73036
|
+
viewport: raw,
|
|
73037
|
+
prod: prod.nodes ? answer(prod.nodes, label, aliases) : { found: false, reason: prod.error ?? "prod unreadable" },
|
|
73038
|
+
cand: cand.nodes ? answer(cand.nodes, label, aliases) : { found: false, reason: cand.error ?? "cand unreadable" }
|
|
73039
|
+
});
|
|
73040
|
+
}
|
|
73041
|
+
}
|
|
73042
|
+
} finally {
|
|
73043
|
+
await browser.close().catch(() => {
|
|
73044
|
+
return;
|
|
73045
|
+
});
|
|
73046
|
+
}
|
|
73047
|
+
const unresolved = results.filter((r) => !r.prod.found || !r.cand.found);
|
|
73048
|
+
if (opts.json) {
|
|
73049
|
+
console.log(JSON.stringify({
|
|
73050
|
+
selector,
|
|
73051
|
+
results: results.map((r) => ({
|
|
73052
|
+
...r,
|
|
73053
|
+
delta: r.prod.found && r.cand.found ? formatDelta(r.prod.hit, r.cand.hit) : null,
|
|
73054
|
+
notes: r.prod.found && r.cand.found ? pairingNotes(r.prod.hit, r.cand.hit) : []
|
|
73055
|
+
})),
|
|
73056
|
+
caveats,
|
|
73057
|
+
unresolved: unresolved.length
|
|
73058
|
+
}));
|
|
73059
|
+
return unresolved.length > 0 ? 1 : 0;
|
|
73060
|
+
}
|
|
73061
|
+
for (const r of results)
|
|
73062
|
+
printResult3(r);
|
|
73063
|
+
for (const c of caveats)
|
|
73064
|
+
console.log(chalk28.yellow(` ${c}`));
|
|
73065
|
+
console.log("");
|
|
73066
|
+
if (unresolved.length > 0) {
|
|
73067
|
+
console.log(chalk28.yellow(` ${unresolved.length} of ${results.length} label×viewport pair${results.length === 1 ? "" : "s"} unresolved — those rows are not a measurement`));
|
|
73068
|
+
} else {
|
|
73069
|
+
console.log(chalk28.green(` ${results.length} label×viewport pair${results.length === 1 ? "" : "s"} located on both sides`));
|
|
73070
|
+
}
|
|
73071
|
+
return unresolved.length > 0 ? 1 : 0;
|
|
73072
|
+
}
|
|
73073
|
+
|
|
73074
|
+
// src/commands/cockpit.ts
|
|
73075
|
+
import { resolve as resolve9 } from "node:path";
|
|
73076
|
+
import chalk29 from "chalk";
|
|
73077
|
+
|
|
73078
|
+
// src/server/cockpit.ts
|
|
73079
|
+
import { createServer as createServer2 } from "node:http";
|
|
73080
|
+
|
|
73081
|
+
// src/server/cockpit-api.ts
|
|
73082
|
+
import { existsSync as existsSync29, readFileSync as readFileSync33, readdirSync as readdirSync7 } from "node:fs";
|
|
73083
|
+
import { join as join39 } from "node:path";
|
|
73084
|
+
var notFound = (what) => ({ status: 404, body: { error: what } });
|
|
73085
|
+
function readJson2(path) {
|
|
73086
|
+
if (!existsSync29(path))
|
|
73087
|
+
return null;
|
|
73088
|
+
try {
|
|
73089
|
+
return JSON.parse(readFileSync33(path, "utf8"));
|
|
73090
|
+
} catch {
|
|
73091
|
+
return null;
|
|
73092
|
+
}
|
|
73093
|
+
}
|
|
73094
|
+
function withPlan(ctx) {
|
|
73095
|
+
return loadPlan(ctx.planDir);
|
|
73096
|
+
}
|
|
73097
|
+
function listBenchResults(benchDir) {
|
|
73098
|
+
if (!existsSync29(benchDir))
|
|
73099
|
+
return [];
|
|
73100
|
+
let files;
|
|
73101
|
+
try {
|
|
73102
|
+
files = readdirSync7(benchDir).filter((f) => f.startsWith("bench-") && f.endsWith(".json"));
|
|
73103
|
+
} catch {
|
|
73104
|
+
return [];
|
|
73105
|
+
}
|
|
73106
|
+
const out = [];
|
|
73107
|
+
for (const file of files) {
|
|
73108
|
+
const raw = readJson2(join39(benchDir, file));
|
|
73109
|
+
if (!raw?.component)
|
|
73110
|
+
continue;
|
|
73111
|
+
out.push({
|
|
73112
|
+
file,
|
|
73113
|
+
component: raw.component,
|
|
73114
|
+
viewport: raw.viewport ?? "?",
|
|
73115
|
+
clean: Boolean(raw.clean),
|
|
73116
|
+
deltas: raw.geometry?.deltas?.length ?? 0,
|
|
73117
|
+
motionFindings: raw.motion?.findings?.length ?? 0
|
|
73118
|
+
});
|
|
73119
|
+
}
|
|
73120
|
+
return out.sort((a, b) => Number(a.clean) - Number(b.clean) || b.deltas - a.deltas || a.component.localeCompare(b.component));
|
|
73121
|
+
}
|
|
73122
|
+
function cockpitApi(path, params, ctx) {
|
|
73123
|
+
switch (path) {
|
|
73124
|
+
case "/api/context":
|
|
73125
|
+
return {
|
|
73126
|
+
status: 200,
|
|
73127
|
+
body: {
|
|
73128
|
+
planDir: ctx.planDir,
|
|
73129
|
+
output: ctx.output,
|
|
73130
|
+
benchDir: ctx.benchDir,
|
|
73131
|
+
prodUrl: ctx.prodUrl ?? null,
|
|
73132
|
+
candUrl: ctx.candUrl ?? null,
|
|
73133
|
+
hasPlan: existsSync29(join39(ctx.planDir, "migration-plan.json"))
|
|
73134
|
+
}
|
|
73135
|
+
};
|
|
73136
|
+
case "/api/state": {
|
|
73137
|
+
const state = readJson2(join39(ctx.planDir, "migration.json"));
|
|
73138
|
+
return state ? { status: 200, body: state } : notFound("no migration.json — no migration has been started here");
|
|
73139
|
+
}
|
|
73140
|
+
case "/api/plan": {
|
|
73141
|
+
const plan = withPlan(ctx);
|
|
73142
|
+
if (!plan)
|
|
73143
|
+
return notFound("no migration-plan.json — run `parity migrate --url <prod>` first");
|
|
73144
|
+
return {
|
|
73145
|
+
status: 200,
|
|
73146
|
+
body: {
|
|
73147
|
+
url: plan.url,
|
|
73148
|
+
target: plan.target.name,
|
|
73149
|
+
source: plan.source,
|
|
73150
|
+
...planProgress(plan),
|
|
73151
|
+
provenance: provenanceCounts(plan),
|
|
73152
|
+
touches: totalTouches(plan)
|
|
73153
|
+
}
|
|
73154
|
+
};
|
|
73155
|
+
}
|
|
73156
|
+
case "/api/board": {
|
|
73157
|
+
const plan = withPlan(ctx);
|
|
73158
|
+
if (!plan)
|
|
73159
|
+
return notFound("no migration-plan.json");
|
|
73160
|
+
return { status: 200, body: planBoard(plan, params.get("candUrl") ?? ctx.candUrl) };
|
|
73161
|
+
}
|
|
73162
|
+
case "/api/page": {
|
|
73163
|
+
const plan = withPlan(ctx);
|
|
73164
|
+
if (!plan)
|
|
73165
|
+
return notFound("no migration-plan.json");
|
|
73166
|
+
const pagePath = params.get("path");
|
|
73167
|
+
if (!pagePath)
|
|
73168
|
+
return { status: 400, body: { error: "missing ?path=" } };
|
|
73169
|
+
const sheet = pagePlan(plan, pagePath, params.get("candUrl") ?? ctx.candUrl);
|
|
73170
|
+
return sheet ? { status: 200, body: sheet } : notFound(`the plan has no page at ${pagePath}`);
|
|
73171
|
+
}
|
|
73172
|
+
case "/api/runs":
|
|
73173
|
+
return { status: 200, body: listRuns(ctx.output).slice(0, 30) };
|
|
73174
|
+
case "/api/run": {
|
|
73175
|
+
const id = params.get("id") ?? listRuns(ctx.output)[0]?.id;
|
|
73176
|
+
if (!id)
|
|
73177
|
+
return notFound("no runs found");
|
|
73178
|
+
try {
|
|
73179
|
+
const run = loadRun(ctx.output, id);
|
|
73180
|
+
return {
|
|
73181
|
+
status: 200,
|
|
73182
|
+
body: {
|
|
73183
|
+
id: run.id,
|
|
73184
|
+
timestamp: run.timestamp,
|
|
73185
|
+
prodUrl: run.prodUrl,
|
|
73186
|
+
candUrl: run.candUrl,
|
|
73187
|
+
verdict: run.verdict,
|
|
73188
|
+
previousRun: run.previousRun ?? null,
|
|
73189
|
+
topIssues: run.topIssues,
|
|
73190
|
+
checks: run.checks.map((c) => ({
|
|
73191
|
+
name: c.name,
|
|
73192
|
+
status: c.status,
|
|
73193
|
+
severity: c.severity,
|
|
73194
|
+
summary: c.summary,
|
|
73195
|
+
issues: c.issues.length
|
|
73196
|
+
}))
|
|
73197
|
+
}
|
|
73198
|
+
};
|
|
73199
|
+
} catch (err) {
|
|
73200
|
+
return notFound(err.message);
|
|
73201
|
+
}
|
|
73202
|
+
}
|
|
73203
|
+
case "/api/bench":
|
|
73204
|
+
return { status: 200, body: listBenchResults(ctx.benchDir) };
|
|
73205
|
+
case "/api/bench/result": {
|
|
73206
|
+
const file = params.get("file");
|
|
73207
|
+
if (!file)
|
|
73208
|
+
return { status: 400, body: { error: "missing ?file=" } };
|
|
73209
|
+
if (file.includes("/") || file.includes("\\") || !/^bench-[\w.-]+\.json$/.test(file)) {
|
|
73210
|
+
return { status: 400, body: { error: "bad file name" } };
|
|
73211
|
+
}
|
|
73212
|
+
const raw = readJson2(join39(ctx.benchDir, file));
|
|
73213
|
+
return raw ? { status: 200, body: raw } : notFound(`no bench result ${file}`);
|
|
73214
|
+
}
|
|
73215
|
+
default:
|
|
73216
|
+
return null;
|
|
73217
|
+
}
|
|
73218
|
+
}
|
|
73219
|
+
|
|
73220
|
+
// src/server/cockpit-html.ts
|
|
73221
|
+
var COCKPIT_HTML = `<!doctype html>
|
|
73222
|
+
<html lang="en">
|
|
73223
|
+
<head>
|
|
73224
|
+
<meta charset="utf-8" />
|
|
73225
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
73226
|
+
<title>parity cockpit</title>
|
|
73227
|
+
<style>
|
|
73228
|
+
:root{
|
|
73229
|
+
--bg:#0e0f11; --panel:#16181c; --panel-2:#1c1f24; --line:#292d34;
|
|
73230
|
+
--ink:#e8eaed; --dim:#9aa0a8; --faint:#6b7280;
|
|
73231
|
+
--ok:#8CAA25; --warn:#FFC116; --bad:#e5534b; --accent:#A595FF;
|
|
73232
|
+
--mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;
|
|
73233
|
+
}
|
|
73234
|
+
@media (prefers-color-scheme: light){
|
|
73235
|
+
:root{--bg:#fbfbfc;--panel:#fff;--panel-2:#f4f5f7;--line:#e3e5e9;--ink:#16181c;--dim:#5c636e;--faint:#8b929c}
|
|
73236
|
+
}
|
|
73237
|
+
*{box-sizing:border-box}
|
|
73238
|
+
body{margin:0;background:var(--bg);color:var(--ink);
|
|
73239
|
+
font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif}
|
|
73240
|
+
a{color:inherit}
|
|
73241
|
+
header.top{display:flex;align-items:center;gap:16px;padding:12px 20px;border-bottom:1px solid var(--line);
|
|
73242
|
+
position:sticky;top:0;background:var(--bg);z-index:10;flex-wrap:wrap}
|
|
73243
|
+
.brand{font-weight:600;letter-spacing:-.01em}
|
|
73244
|
+
.brand span{color:var(--faint);font-weight:400}
|
|
73245
|
+
nav.tabs{display:flex;gap:4px;margin-left:8px}
|
|
73246
|
+
nav.tabs button{background:none;border:1px solid transparent;color:var(--dim);padding:5px 11px;
|
|
73247
|
+
border-radius:7px;cursor:pointer;font:inherit}
|
|
73248
|
+
nav.tabs button[aria-selected="true"]{background:var(--panel-2);border-color:var(--line);color:var(--ink)}
|
|
73249
|
+
.spacer{flex:1}
|
|
73250
|
+
.meta{color:var(--faint);font:12px/1.4 var(--mono)}
|
|
73251
|
+
main{padding:20px;max-width:1600px;margin:0 auto}
|
|
73252
|
+
.view[hidden]{display:none}
|
|
73253
|
+
h2{font-size:15px;margin:0 0 12px;font-weight:600}
|
|
73254
|
+
.sub{color:var(--dim);margin:-8px 0 16px}
|
|
73255
|
+
|
|
73256
|
+
/* stat strip */
|
|
73257
|
+
.stats{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:20px}
|
|
73258
|
+
.stat{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:11px 14px;min-width:120px}
|
|
73259
|
+
.stat b{display:block;font-size:20px;font-variant-numeric:tabular-nums;letter-spacing:-.02em}
|
|
73260
|
+
.stat small{color:var(--faint);font-size:11px;text-transform:uppercase;letter-spacing:.05em}
|
|
73261
|
+
|
|
73262
|
+
/* board */
|
|
73263
|
+
.lanes{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:14px;align-items:start}
|
|
73264
|
+
.lane{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:12px}
|
|
73265
|
+
.lane h3{margin:0 0 10px;font-size:12px;text-transform:uppercase;letter-spacing:.06em;color:var(--dim);
|
|
73266
|
+
display:flex;justify-content:space-between;align-items:center}
|
|
73267
|
+
.lane h3 em{font-style:normal;color:var(--faint);font-variant-numeric:tabular-nums}
|
|
73268
|
+
.card{background:var(--panel-2);border:1px solid var(--line);border-radius:9px;padding:10px;margin-bottom:8px;
|
|
73269
|
+
cursor:pointer;text-align:left;width:100%;color:inherit;font:inherit;display:block}
|
|
73270
|
+
.card:hover{border-color:var(--accent)}
|
|
73271
|
+
.card:last-child{margin-bottom:0}
|
|
73272
|
+
.card .path{font-family:var(--mono);font-size:12px}
|
|
73273
|
+
.card .why{color:var(--dim);font-size:12px;margin-top:5px}
|
|
73274
|
+
.empty{color:var(--faint);font-size:12px;font-style:italic}
|
|
73275
|
+
|
|
73276
|
+
.chip{display:inline-block;padding:1px 7px;border-radius:999px;font-size:11px;border:1px solid var(--line);
|
|
73277
|
+
color:var(--dim);font-family:var(--mono)}
|
|
73278
|
+
.chip.ok{color:var(--ok);border-color:color-mix(in srgb,var(--ok) 40%,transparent)}
|
|
73279
|
+
.chip.warn{color:var(--warn);border-color:color-mix(in srgb,var(--warn) 40%,transparent)}
|
|
73280
|
+
.chip.bad{color:var(--bad);border-color:color-mix(in srgb,var(--bad) 40%,transparent)}
|
|
73281
|
+
|
|
73282
|
+
/* diff */
|
|
73283
|
+
.diffgrid{display:grid;grid-template-columns:280px 1fr;gap:14px;align-items:start}
|
|
73284
|
+
.list{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:8px;
|
|
73285
|
+
max-height:75vh;overflow:auto}
|
|
73286
|
+
.list button{display:block;width:100%;text-align:left;background:none;border:0;color:inherit;font:inherit;
|
|
73287
|
+
padding:8px 9px;border-radius:7px;cursor:pointer}
|
|
73288
|
+
.list button:hover{background:var(--panel-2)}
|
|
73289
|
+
.list button[aria-selected="true"]{background:var(--panel-2);box-shadow:inset 2px 0 0 var(--accent)}
|
|
73290
|
+
.list .name{font-family:var(--mono);font-size:12px}
|
|
73291
|
+
.list .row2{display:flex;gap:6px;align-items:center;margin-top:4px}
|
|
73292
|
+
|
|
73293
|
+
table{width:100%;border-collapse:collapse;font-family:var(--mono);font-size:12px}
|
|
73294
|
+
th{text-align:left;color:var(--faint);font-weight:500;padding:6px 10px;border-bottom:1px solid var(--line);
|
|
73295
|
+
position:sticky;top:0;background:var(--panel);text-transform:uppercase;font-size:10px;letter-spacing:.06em}
|
|
73296
|
+
td{padding:6px 10px;border-bottom:1px solid color-mix(in srgb,var(--line) 55%,transparent);vertical-align:top}
|
|
73297
|
+
tr:last-child td{border-bottom:0}
|
|
73298
|
+
td.sel{color:var(--dim);word-break:break-all}
|
|
73299
|
+
td.prop{color:var(--ink)}
|
|
73300
|
+
td.num{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
73301
|
+
.delta{font-weight:600}
|
|
73302
|
+
.delta.neg{color:var(--bad)}
|
|
73303
|
+
.delta.pos{color:var(--warn)}
|
|
73304
|
+
.panel{background:var(--panel);border:1px solid var(--line);border-radius:12px;overflow:hidden}
|
|
73305
|
+
.panel .hd{padding:11px 14px;border-bottom:1px solid var(--line);display:flex;gap:10px;align-items:center;
|
|
73306
|
+
flex-wrap:wrap}
|
|
73307
|
+
.panel .hd b{font-size:13px}
|
|
73308
|
+
.panel .bd{max-height:60vh;overflow:auto}
|
|
73309
|
+
.motion{padding:0}
|
|
73310
|
+
.motion li{list-style:none;padding:8px 14px;border-bottom:1px solid color-mix(in srgb,var(--line) 55%,transparent);
|
|
73311
|
+
display:grid;grid-template-columns:200px 150px 1fr;gap:10px;font-size:12px}
|
|
73312
|
+
.motion li:last-child{border-bottom:0}
|
|
73313
|
+
.motion .k{font-family:var(--mono);color:var(--dim);word-break:break-all}
|
|
73314
|
+
|
|
73315
|
+
/* panes */
|
|
73316
|
+
.panes{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-top:14px}
|
|
73317
|
+
.pane{background:var(--panel);border:1px solid var(--line);border-radius:12px;overflow:hidden}
|
|
73318
|
+
.pane .hd{padding:8px 12px;border-bottom:1px solid var(--line);font:11px/1.4 var(--mono);color:var(--dim);
|
|
73319
|
+
display:flex;justify-content:space-between;gap:8px}
|
|
73320
|
+
.pane iframe{width:100%;height:52vh;border:0;background:#fff;display:block}
|
|
73321
|
+
.note{background:var(--panel);border:1px dashed var(--line);border-radius:12px;padding:16px;color:var(--dim)}
|
|
73322
|
+
.note code{font-family:var(--mono);color:var(--ink);background:var(--panel-2);padding:1px 5px;border-radius:4px}
|
|
73323
|
+
.err{color:var(--bad)}
|
|
73324
|
+
</style>
|
|
73325
|
+
</head>
|
|
73326
|
+
<body>
|
|
73327
|
+
<header class="top">
|
|
73328
|
+
<div class="brand">parity <span id="ver"></span></div>
|
|
73329
|
+
<nav class="tabs" role="tablist">
|
|
73330
|
+
<button role="tab" data-view="board" aria-selected="true">Board</button>
|
|
73331
|
+
<button role="tab" data-view="diff" aria-selected="false">Diff</button>
|
|
73332
|
+
<button role="tab" data-view="run" aria-selected="false">Run</button>
|
|
73333
|
+
</nav>
|
|
73334
|
+
<div class="spacer"></div>
|
|
73335
|
+
<div class="meta" id="ctx"></div>
|
|
73336
|
+
</header>
|
|
73337
|
+
|
|
73338
|
+
<main>
|
|
73339
|
+
<section class="view" id="view-board">
|
|
73340
|
+
<div class="stats" id="stats"></div>
|
|
73341
|
+
<h2 id="board-title">Pages</h2>
|
|
73342
|
+
<p class="sub" id="board-sub"></p>
|
|
73343
|
+
<div class="lanes" id="lanes"></div>
|
|
73344
|
+
<div id="shell"></div>
|
|
73345
|
+
</section>
|
|
73346
|
+
|
|
73347
|
+
<section class="view" id="view-diff" hidden>
|
|
73348
|
+
<h2>Component diffs</h2>
|
|
73349
|
+
<p class="sub">From <code>parity bench</code> results on disk. Dirty first.</p>
|
|
73350
|
+
<div class="diffgrid">
|
|
73351
|
+
<div class="list" id="bench-list"></div>
|
|
73352
|
+
<div id="bench-detail"></div>
|
|
73353
|
+
</div>
|
|
73354
|
+
</section>
|
|
73355
|
+
|
|
73356
|
+
<section class="view" id="view-run" hidden>
|
|
73357
|
+
<h2>Latest run</h2>
|
|
73358
|
+
<div id="run-detail"></div>
|
|
73359
|
+
</section>
|
|
73360
|
+
</main>
|
|
73361
|
+
|
|
73362
|
+
<script>
|
|
73363
|
+
const $ = (s, r = document) => r.querySelector(s);
|
|
73364
|
+
const el = (t, props = {}, kids = []) => {
|
|
73365
|
+
const n = Object.assign(document.createElement(t), props);
|
|
73366
|
+
for (const k of [].concat(kids)) n.append(k);
|
|
73367
|
+
return n;
|
|
73368
|
+
};
|
|
73369
|
+
// Every value from the API lands in the DOM as TEXT, never as HTML. The server
|
|
73370
|
+
// reads a client's repo — component names, page paths and CSS selectors are
|
|
73371
|
+
// their content, not ours.
|
|
73372
|
+
const txt = (v) => document.createTextNode(String(v ?? ""));
|
|
73373
|
+
|
|
73374
|
+
const api = async (path) => {
|
|
73375
|
+
const r = await fetch(path);
|
|
73376
|
+
const body = await r.json().catch(() => ({ error: "unreadable response" }));
|
|
73377
|
+
return { ok: r.ok, body };
|
|
73378
|
+
};
|
|
73379
|
+
|
|
73380
|
+
let CTX = {};
|
|
73381
|
+
|
|
73382
|
+
function show(view) {
|
|
73383
|
+
for (const b of document.querySelectorAll("nav.tabs button"))
|
|
73384
|
+
b.setAttribute("aria-selected", String(b.dataset.view === view));
|
|
73385
|
+
for (const s of document.querySelectorAll(".view")) s.hidden = s.id !== \`view-\${view}\`;
|
|
73386
|
+
if (view === "diff") loadBench();
|
|
73387
|
+
if (view === "run") loadRun();
|
|
73388
|
+
}
|
|
73389
|
+
for (const b of document.querySelectorAll("nav.tabs button"))
|
|
73390
|
+
b.addEventListener("click", () => show(b.dataset.view));
|
|
73391
|
+
|
|
73392
|
+
function note(parent, msg, hint) {
|
|
73393
|
+
parent.replaceChildren(
|
|
73394
|
+
el("div", { className: "note" }, [el("div", {}, txt(msg)), hint ? el("p", {}, hint) : ""]),
|
|
73395
|
+
);
|
|
73396
|
+
}
|
|
73397
|
+
|
|
73398
|
+
const LANES = [
|
|
73399
|
+
["backlog", "Backlog"],
|
|
73400
|
+
["building", "Building"],
|
|
73401
|
+
["triage", "Triage"],
|
|
73402
|
+
["review", "Review"],
|
|
73403
|
+
["done", "Done"],
|
|
73404
|
+
["skipped", "Skipped"],
|
|
73405
|
+
];
|
|
73406
|
+
|
|
73407
|
+
async function loadBoard() {
|
|
73408
|
+
const [plan, board] = await Promise.all([api("/api/plan"), api("/api/board")]);
|
|
73409
|
+
const stats = $("#stats");
|
|
73410
|
+
if (!plan.ok) {
|
|
73411
|
+
stats.replaceChildren();
|
|
73412
|
+
note(
|
|
73413
|
+
$("#lanes"),
|
|
73414
|
+
plan.body.error || "no plan",
|
|
73415
|
+
el("span", {}, [
|
|
73416
|
+
txt("Run "),
|
|
73417
|
+
el("code", {}, txt("parity migrate --url <prod>")),
|
|
73418
|
+
txt(" first — without a plan there is no inventory, and a survey without one silently reports zero missing components."),
|
|
73419
|
+
]),
|
|
73420
|
+
);
|
|
73421
|
+
return;
|
|
73422
|
+
}
|
|
73423
|
+
const p = plan.body;
|
|
73424
|
+
const stat = (n, label) => el("div", { className: "stat" }, [el("b", {}, txt(n)), el("small", {}, txt(label))]);
|
|
73425
|
+
const c = p.components || {};
|
|
73426
|
+
stats.replaceChildren(
|
|
73427
|
+
stat(\`\${c.byStatus?.done ?? 0}/\${c.total ?? 0}\`, "components done"),
|
|
73428
|
+
stat(c.byStatus?.pending ?? 0, "pending"),
|
|
73429
|
+
stat(\`\${p.provenance?.library ?? 0}/\${(p.provenance?.library ?? 0) + (p.provenance?.built ?? 0)}\`, "from library"),
|
|
73430
|
+
stat(p.touches ?? 0, "human touches"),
|
|
73431
|
+
);
|
|
73432
|
+
$("#board-sub").replaceChildren(
|
|
73433
|
+
txt(\`\${p.url}\${p.target ? \` → \${p.target}\` : ""} · \${board.ok ? board.body.sampled : 0} pages sampled\`),
|
|
73434
|
+
);
|
|
73435
|
+
|
|
73436
|
+
if (!board.ok) return note($("#lanes"), board.body.error || "no board");
|
|
73437
|
+
const lanes = $("#lanes");
|
|
73438
|
+
lanes.replaceChildren();
|
|
73439
|
+
const cards = board.body.columns || {};
|
|
73440
|
+
for (const [key, label] of LANES) {
|
|
73441
|
+
const items = cards[key] || [];
|
|
73442
|
+
if (!items.length && (key === "skipped" || key === "triage")) continue;
|
|
73443
|
+
const lane = el("div", { className: "lane" }, [
|
|
73444
|
+
el("h3", {}, [txt(label), el("em", {}, txt(items.length))]),
|
|
73445
|
+
]);
|
|
73446
|
+
if (!items.length) lane.append(el("div", { className: "empty" }, txt("nothing here")));
|
|
73447
|
+
for (const item of items) {
|
|
73448
|
+
const btn = el("button", { className: "card", type: "button" }, [
|
|
73449
|
+
el("div", { className: "path" }, txt(item.path)),
|
|
73450
|
+
]);
|
|
73451
|
+
const counts = item.counts || {};
|
|
73452
|
+
// blockers is page-scope only, by design: globals block every page, so
|
|
73453
|
+
// repeating them per card is noise. They show in the Shell strip instead.
|
|
73454
|
+
const why = item.blockers?.length
|
|
73455
|
+
? \`blocked by \${item.blockers.join(", ")}\`
|
|
73456
|
+
: counts.validate
|
|
73457
|
+
? \`\${counts.validate} to validate\`
|
|
73458
|
+
: item.ready
|
|
73459
|
+
? "nothing left to build or validate"
|
|
73460
|
+
: "";
|
|
73461
|
+
const meta = el("div", { className: "row2", style: "margin-top:6px" }, [
|
|
73462
|
+
el("span", { className: "chip" }, txt(item.kind)),
|
|
73463
|
+
]);
|
|
73464
|
+
if (counts.build) meta.append(el("span", { className: "chip bad" }, txt(\`\${counts.build} to build\`)));
|
|
73465
|
+
if (counts["as-is"]) meta.append(el("span", { className: "chip" }, txt(\`\${counts["as-is"]} as-is\`)));
|
|
73466
|
+
if (counts.upgrade) meta.append(el("span", { className: "chip warn" }, txt(\`\${counts.upgrade} upgrade\`)));
|
|
73467
|
+
if (why) btn.append(el("div", { className: "why" }, txt(why)));
|
|
73468
|
+
btn.append(meta);
|
|
73469
|
+
btn.addEventListener("click", () => loadPage(item.path));
|
|
73470
|
+
lane.append(btn);
|
|
73471
|
+
}
|
|
73472
|
+
lanes.append(lane);
|
|
73473
|
+
}
|
|
73474
|
+
|
|
73475
|
+
const shellItems = board.body.shell || [];
|
|
73476
|
+
const noPage = board.body.unassigned || [];
|
|
73477
|
+
const extra = $("#shell");
|
|
73478
|
+
extra.replaceChildren();
|
|
73479
|
+
const strip = (title, list, hint) => {
|
|
73480
|
+
if (!list.length) return;
|
|
73481
|
+
const box = el("div", { className: "lane", style: "margin-top:14px" }, [
|
|
73482
|
+
el("h3", {}, [txt(title), el("em", {}, txt(list.length))]),
|
|
73483
|
+
el("p", { className: "why", style: "margin:0 0 8px" }, txt(hint)),
|
|
73484
|
+
]);
|
|
73485
|
+
for (const s of list)
|
|
73486
|
+
box.append(el("span", { className: "chip", style: "margin:0 4px 4px 0" }, txt(s.name ?? s)));
|
|
73487
|
+
extra.append(box);
|
|
73488
|
+
};
|
|
73489
|
+
strip("Shell", shellItems, "Globals. They block every page at once, so they are reported once instead of on each card.");
|
|
73490
|
+
strip("No page", noPage, "Components the code defines that no sampled page uses. Listed rather than hidden: real work with no lane.");
|
|
73491
|
+
}
|
|
73492
|
+
|
|
73493
|
+
async function loadPage(path) {
|
|
73494
|
+
const r = await api(\`/api/page?path=\${encodeURIComponent(path)}\`);
|
|
73495
|
+
show("diff");
|
|
73496
|
+
const box = $("#bench-detail");
|
|
73497
|
+
if (!r.ok) return note(box, r.body.error || "no worksheet");
|
|
73498
|
+
const w = r.body;
|
|
73499
|
+
const DISP = { build: "bad", validate: "warn", upgrade: "warn", "as-is": "", settled: "ok" };
|
|
73500
|
+
const rows = (w.tasks || []).map((t) =>
|
|
73501
|
+
el("tr", {}, [
|
|
73502
|
+
el("td", { className: "prop" }, txt(t.name)),
|
|
73503
|
+
el("td", {}, el("span", { className: \`chip \${DISP[t.disposition] ?? ""}\`}, txt(t.disposition))),
|
|
73504
|
+
el("td", { className: "sel" }, txt(t.against ? \`\${t.against.kind}: \${t.against.url}\` : "")),
|
|
73505
|
+
// The worksheet already built the command; showing it is what makes this
|
|
73506
|
+
// a place to work from rather than a status page.
|
|
73507
|
+
el("td", { className: "sel" }, txt(t.command || t.note || "")),
|
|
73508
|
+
]),
|
|
73509
|
+
);
|
|
73510
|
+
box.replaceChildren(
|
|
73511
|
+
el("div", { className: "panel" }, [
|
|
73512
|
+
el("div", { className: "hd" }, [
|
|
73513
|
+
el("b", {}, txt(path)),
|
|
73514
|
+
el("span", { className: \`chip \${w.ready ? "ok" : "warn"}\` }, txt(w.ready ? "ready" : "not ready")),
|
|
73515
|
+
]),
|
|
73516
|
+
el("div", { className: "bd" }, [
|
|
73517
|
+
el("table", {}, [
|
|
73518
|
+
el("thead", {}, el("tr", {}, [
|
|
73519
|
+
el("th", {}, txt("component")),
|
|
73520
|
+
el("th", {}, txt("disposition")),
|
|
73521
|
+
el("th", {}, txt("measured against")),
|
|
73522
|
+
el("th", {}, txt("command")),
|
|
73523
|
+
])),
|
|
73524
|
+
el("tbody", {}, rows.length ? rows : el("tr", {}, el("td", { colSpan: 4 },
|
|
73525
|
+
// Not the same as "nothing to do": the capture saw no components on
|
|
73526
|
+
// this page, so its scope is unconfirmed. That is the triage lane.
|
|
73527
|
+
txt("the capture recorded no components for this page — scope unconfirmed, not done")))),
|
|
73528
|
+
]),
|
|
73529
|
+
]),
|
|
73530
|
+
]),
|
|
73531
|
+
);
|
|
73532
|
+
}
|
|
73533
|
+
|
|
73534
|
+
async function loadBench() {
|
|
73535
|
+
const list = $("#bench-list");
|
|
73536
|
+
const r = await api("/api/bench");
|
|
73537
|
+
if (!r.ok || !r.body.length) {
|
|
73538
|
+
list.replaceChildren(el("div", { className: "empty", style: "padding:10px" }, txt("no bench results yet")));
|
|
73539
|
+
note(
|
|
73540
|
+
$("#bench-detail"),
|
|
73541
|
+
"Nothing benched yet.",
|
|
73542
|
+
el("span", {}, [
|
|
73543
|
+
txt("Run "),
|
|
73544
|
+
el("code", {}, txt("parity bench --component <Name> --prod <ref> --cand <target>")),
|
|
73545
|
+
txt(" — it writes one JSON per component into the bench dir this cockpit is watching."),
|
|
73546
|
+
]),
|
|
73547
|
+
);
|
|
73548
|
+
return;
|
|
73549
|
+
}
|
|
73550
|
+
list.replaceChildren();
|
|
73551
|
+
for (const b of r.body) {
|
|
73552
|
+
const btn = el("button", { type: "button", "aria-selected": "false" }, [
|
|
73553
|
+
el("div", { className: "name" }, txt(b.component)),
|
|
73554
|
+
el("div", { className: "row2" }, [
|
|
73555
|
+
el("span", { className: \`chip \${b.clean ? "ok" : "bad"}\` }, txt(b.clean ? "clean" : \`\${b.deltas} deltas\`)),
|
|
73556
|
+
b.motionFindings ? el("span", { className: "chip warn" }, txt(\`\${b.motionFindings} motion\`)) : "",
|
|
73557
|
+
el("span", { className: "chip" }, txt(b.viewport)),
|
|
73558
|
+
]),
|
|
73559
|
+
]);
|
|
73560
|
+
btn.addEventListener("click", () => {
|
|
73561
|
+
for (const o of list.querySelectorAll("button")) o.setAttribute("aria-selected", "false");
|
|
73562
|
+
btn.setAttribute("aria-selected", "true");
|
|
73563
|
+
loadBenchResult(b.file);
|
|
73564
|
+
});
|
|
73565
|
+
list.append(btn);
|
|
73566
|
+
}
|
|
73567
|
+
list.querySelector("button")?.click();
|
|
73568
|
+
}
|
|
73569
|
+
|
|
73570
|
+
async function loadBenchResult(file) {
|
|
73571
|
+
const box = $("#bench-detail");
|
|
73572
|
+
const r = await api(\`/api/bench/result?file=\${encodeURIComponent(file)}\`);
|
|
73573
|
+
if (!r.ok) return note(box, r.body.error || "unreadable");
|
|
73574
|
+
const d = r.body;
|
|
73575
|
+
const deltas = d.geometry?.deltas || [];
|
|
73576
|
+
const rows = deltas.map((x) =>
|
|
73577
|
+
el("tr", {}, [
|
|
73578
|
+
el("td", { className: "sel" }, txt(x.key)),
|
|
73579
|
+
el("td", { className: "prop" }, txt(x.prop)),
|
|
73580
|
+
el("td", { className: "num" }, txt(x.prod)),
|
|
73581
|
+
el("td", { className: "num" }, txt(x.cand)),
|
|
73582
|
+
el("td", {
|
|
73583
|
+
className: \`num delta \${x.deltaPx == null ? "" : x.deltaPx < 0 ? "neg" : "pos"}\`,
|
|
73584
|
+
}, txt(x.deltaPx == null ? "—" : (x.deltaPx > 0 ? \`+\${x.deltaPx}\` : x.deltaPx))),
|
|
73585
|
+
]),
|
|
73586
|
+
);
|
|
73587
|
+
|
|
73588
|
+
const kids = [
|
|
73589
|
+
el("div", { className: "panel" }, [
|
|
73590
|
+
el("div", { className: "hd" }, [
|
|
73591
|
+
el("b", {}, txt(\`Component \${d.component}\`)),
|
|
73592
|
+
el("span", { className: \`chip \${d.clean ? "ok" : "bad"}\` }, txt(d.clean ? "clean" : \`\${deltas.length} deltas left\`)),
|
|
73593
|
+
el("span", { className: "chip" }, txt(d.viewport)),
|
|
73594
|
+
d.geometry?.truncated ? el("span", { className: "chip warn" }, txt("truncated — absence is not proof")) : "",
|
|
73595
|
+
]),
|
|
73596
|
+
el("div", { className: "bd" }, [
|
|
73597
|
+
el("table", {}, [
|
|
73598
|
+
el("thead", {}, el("tr", {}, [
|
|
73599
|
+
el("th", {}, txt("selector")),
|
|
73600
|
+
el("th", {}, txt("property")),
|
|
73601
|
+
el("th", { style: "text-align:right" }, txt("prod")),
|
|
73602
|
+
el("th", { style: "text-align:right" }, txt("cand")),
|
|
73603
|
+
el("th", { style: "text-align:right" }, txt("Δ")),
|
|
73604
|
+
])),
|
|
73605
|
+
el("tbody", {}, rows.length ? rows : el("tr", {}, el("td", { colSpan: 5 }, txt("geometry clean")))),
|
|
73606
|
+
]),
|
|
73607
|
+
]),
|
|
73608
|
+
]),
|
|
73609
|
+
];
|
|
73610
|
+
|
|
73611
|
+
const findings = d.motion?.findings || [];
|
|
73612
|
+
if (findings.length) {
|
|
73613
|
+
const ul = el("ul", { className: "motion" });
|
|
73614
|
+
for (const f of findings)
|
|
73615
|
+
ul.append(el("li", {}, [
|
|
73616
|
+
el("span", { className: "k" }, txt(f.key)),
|
|
73617
|
+
el("span", { className: \`chip \${f.kind.startsWith("missing") ? "bad" : "warn"}\` }, txt(f.kind)),
|
|
73618
|
+
el("span", {}, txt(f.detail)),
|
|
73619
|
+
]));
|
|
73620
|
+
kids.push(el("div", { className: "panel", style: "margin-top:14px" }, [
|
|
73621
|
+
el("div", { className: "hd" }, [el("b", {}, txt("Motion")), el("span", { className: "chip bad" }, txt(\`\${findings.length} findings\`))]),
|
|
73622
|
+
ul,
|
|
73623
|
+
]));
|
|
73624
|
+
}
|
|
73625
|
+
|
|
73626
|
+
// Side-by-side only when both URLs are known: an iframe pointed at nothing
|
|
73627
|
+
// renders a browser error page that reads like a broken candidate.
|
|
73628
|
+
if (CTX.prodUrl && CTX.candUrl) {
|
|
73629
|
+
const pane = (label, url) =>
|
|
73630
|
+
el("div", { className: "pane" }, [
|
|
73631
|
+
el("div", { className: "hd" }, [el("span", {}, txt(label)), el("span", {}, txt(url))]),
|
|
73632
|
+
el("iframe", { src: \`/proxy?url=\${encodeURIComponent(url)}\`, loading: "lazy", referrerPolicy: "no-referrer" }),
|
|
73633
|
+
]);
|
|
73634
|
+
kids.push(el("div", { className: "panes" }, [pane("prod", CTX.prodUrl), pane("cand", CTX.candUrl)]));
|
|
73635
|
+
}
|
|
73636
|
+
box.replaceChildren(...kids);
|
|
73637
|
+
}
|
|
73638
|
+
|
|
73639
|
+
async function loadRun() {
|
|
73640
|
+
const box = $("#run-detail");
|
|
73641
|
+
const r = await api("/api/run");
|
|
73642
|
+
if (!r.ok) {
|
|
73643
|
+
return note(box, r.body.error || "no runs", el("span", {}, [
|
|
73644
|
+
txt("Run "), el("code", {}, txt("parity run --prod <url> --cand <url>")), txt(" to produce one."),
|
|
73645
|
+
]));
|
|
73646
|
+
}
|
|
73647
|
+
const run = r.body;
|
|
73648
|
+
const v = run.verdict || {};
|
|
73649
|
+
const cls = v.status === "pass" ? "ok" : v.status === "fail" ? "bad" : "warn";
|
|
73650
|
+
const trend = run.previousRun ? \` (\${run.previousRun.scoreDelta >= 0 ? "+" : ""}\${run.previousRun.scoreDelta} vs previous)\` : "";
|
|
73651
|
+
const checkRows = (run.checks || []).map((c) =>
|
|
73652
|
+
el("tr", {}, [
|
|
73653
|
+
el("td", { className: "prop" }, txt(c.name)),
|
|
73654
|
+
el("td", {}, el("span", { className: \`chip \${c.status === "pass" ? "ok" : c.status === "fail" ? "bad" : "warn"}\` }, txt(c.status))),
|
|
73655
|
+
el("td", { className: "num" }, txt(c.issues)),
|
|
73656
|
+
el("td", { className: "sel" }, txt(c.summary)),
|
|
73657
|
+
]),
|
|
73658
|
+
);
|
|
73659
|
+
box.replaceChildren(
|
|
73660
|
+
el("div", { className: "stats" }, [
|
|
73661
|
+
el("div", { className: "stat" }, [el("b", {}, txt(\`\${v.score ?? "?"}\${trend}\`)), el("small", {}, txt("score"))]),
|
|
73662
|
+
el("div", { className: "stat" }, [el("b", {}, txt(v.critical ?? 0)), el("small", {}, txt("critical"))]),
|
|
73663
|
+
el("div", { className: "stat" }, [el("b", {}, txt(v.high ?? 0)), el("small", {}, txt("high"))]),
|
|
73664
|
+
el("div", { className: "stat" }, [el("b", {}, txt(\`\${v.checksPassed ?? 0}/\${v.checksRun ?? 0}\`)), el("small", {}, txt("checks passed"))]),
|
|
73665
|
+
]),
|
|
73666
|
+
el("div", { className: "panel" }, [
|
|
73667
|
+
el("div", { className: "hd" }, [
|
|
73668
|
+
el("b", {}, txt(run.id)),
|
|
73669
|
+
el("span", { className: \`chip \${cls}\` }, txt(v.status ?? "?")),
|
|
73670
|
+
el("span", { className: "chip" }, txt(new Date(run.timestamp).toLocaleString())),
|
|
73671
|
+
]),
|
|
73672
|
+
el("div", { className: "bd" }, [
|
|
73673
|
+
el("table", {}, [
|
|
73674
|
+
el("thead", {}, el("tr", {}, [
|
|
73675
|
+
el("th", {}, txt("check")), el("th", {}, txt("status")),
|
|
73676
|
+
el("th", { style: "text-align:right" }, txt("issues")), el("th", {}, txt("summary")),
|
|
73677
|
+
])),
|
|
73678
|
+
el("tbody", {}, checkRows),
|
|
73679
|
+
]),
|
|
73680
|
+
]),
|
|
73681
|
+
]),
|
|
73682
|
+
);
|
|
73683
|
+
}
|
|
73684
|
+
|
|
73685
|
+
(async () => {
|
|
73686
|
+
const r = await api("/api/context");
|
|
73687
|
+
CTX = r.ok ? r.body : {};
|
|
73688
|
+
$("#ctx").replaceChildren(txt(\`\${CTX.planDir ?? ""}\`));
|
|
73689
|
+
const s = await api("/api/state");
|
|
73690
|
+
if (s.ok) $("#ver").replaceChildren(txt(\`· \${s.body.phase ?? ""}\${s.body.stage ? \` / \${s.body.stage}\` : ""}\`));
|
|
73691
|
+
loadBoard();
|
|
73692
|
+
})();
|
|
73693
|
+
</script>
|
|
73694
|
+
</body>
|
|
73695
|
+
</html>
|
|
73696
|
+
`;
|
|
73697
|
+
|
|
73698
|
+
// src/server/cockpit.ts
|
|
73699
|
+
async function startCockpit(ctx, opts = {}) {
|
|
73700
|
+
const server = createServer2((req, res) => {
|
|
73701
|
+
handle(req, res, ctx).catch((err) => {
|
|
73702
|
+
try {
|
|
73703
|
+
res.statusCode = 500;
|
|
73704
|
+
res.setHeader("content-type", "application/json");
|
|
73705
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
73706
|
+
} catch {}
|
|
73707
|
+
});
|
|
73708
|
+
});
|
|
73709
|
+
await new Promise((ready, reject) => {
|
|
73710
|
+
server.once("error", reject);
|
|
73711
|
+
server.listen(opts.port ?? 0, opts.host ?? "127.0.0.1", () => ready());
|
|
73712
|
+
});
|
|
73713
|
+
const addr = server.address();
|
|
73714
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
73715
|
+
const host = opts.host ?? "127.0.0.1";
|
|
73716
|
+
return {
|
|
73717
|
+
port,
|
|
73718
|
+
url: `http://${host}:${port}/`,
|
|
73719
|
+
close: () => new Promise((done) => {
|
|
73720
|
+
try {
|
|
73721
|
+
server.closeAllConnections?.();
|
|
73722
|
+
server.closeIdleConnections?.();
|
|
73723
|
+
} catch {}
|
|
73724
|
+
server.close(() => done());
|
|
73725
|
+
setTimeout(() => done(), 1000);
|
|
73726
|
+
})
|
|
73727
|
+
};
|
|
73728
|
+
}
|
|
73729
|
+
async function handle(req, res, ctx) {
|
|
73730
|
+
const url = new URL(req.url ?? "/", "http://placeholder");
|
|
73731
|
+
const path = decodeURIComponent(url.pathname);
|
|
73732
|
+
const api = cockpitApi(path, url.searchParams, ctx);
|
|
73733
|
+
if (api) {
|
|
73734
|
+
res.statusCode = api.status;
|
|
73735
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
73736
|
+
res.setHeader("cache-control", "no-store");
|
|
73737
|
+
res.end(JSON.stringify(api.body));
|
|
73738
|
+
return;
|
|
73739
|
+
}
|
|
73740
|
+
if (path === "/proxy") {
|
|
73741
|
+
const target = url.searchParams.get("url");
|
|
73742
|
+
if (!target) {
|
|
73743
|
+
res.statusCode = 400;
|
|
73744
|
+
res.end("missing ?url=");
|
|
73745
|
+
return;
|
|
73746
|
+
}
|
|
73747
|
+
return proxyRequest(req, res, target, {
|
|
73748
|
+
forceMobile: url.searchParams.get("viewport") === "mobile"
|
|
73749
|
+
});
|
|
73750
|
+
}
|
|
73751
|
+
if (path === "/" || path === "/index.html") {
|
|
73752
|
+
res.statusCode = 200;
|
|
73753
|
+
res.setHeader("content-type", "text/html; charset=utf-8");
|
|
73754
|
+
res.setHeader("cache-control", "no-store");
|
|
73755
|
+
res.end(COCKPIT_HTML);
|
|
73756
|
+
return;
|
|
73757
|
+
}
|
|
73758
|
+
res.statusCode = 404;
|
|
73759
|
+
res.setHeader("content-type", "application/json");
|
|
73760
|
+
res.end(JSON.stringify({ error: `no route ${path}` }));
|
|
73761
|
+
}
|
|
73762
|
+
|
|
73763
|
+
// src/commands/cockpit.ts
|
|
73764
|
+
async function cockpitCommand(opts) {
|
|
73765
|
+
const ctx = {
|
|
73766
|
+
planDir: resolve9(opts.dir),
|
|
73767
|
+
output: resolve9(opts.output),
|
|
73768
|
+
benchDir: resolve9(opts.benchDir),
|
|
73769
|
+
prodUrl: opts.prodUrl,
|
|
73770
|
+
candUrl: opts.candUrl
|
|
73771
|
+
};
|
|
73772
|
+
let handle;
|
|
73773
|
+
try {
|
|
73774
|
+
handle = await startCockpit(ctx, {
|
|
73775
|
+
port: opts.port ? Number.parseInt(opts.port, 10) : undefined,
|
|
73776
|
+
host: opts.host
|
|
73777
|
+
});
|
|
73778
|
+
} catch (err) {
|
|
73779
|
+
console.error(chalk29.red(` ✖ could not start the cockpit: ${err.message}`));
|
|
73780
|
+
return 2;
|
|
73781
|
+
}
|
|
73782
|
+
console.log("");
|
|
73783
|
+
console.log(chalk29.bold(" parity cockpit"));
|
|
73784
|
+
console.log(` ${chalk29.green("●")} ${handle.url}`);
|
|
73785
|
+
console.log(chalk29.dim(` plan ${ctx.planDir}`));
|
|
73786
|
+
console.log(chalk29.dim(` runs ${ctx.output}`));
|
|
73787
|
+
console.log(chalk29.dim(` bench ${ctx.benchDir}`));
|
|
73788
|
+
if (opts.host && opts.host !== "127.0.0.1" && opts.host !== "localhost") {
|
|
73789
|
+
console.log(chalk29.yellow(` ⚠ bound to ${opts.host} — this server is unauthenticated, reads the repo, and proxies arbitrary URLs`));
|
|
73790
|
+
}
|
|
73791
|
+
console.log(chalk29.dim(` Ctrl+C to stop.
|
|
73792
|
+
`));
|
|
73793
|
+
if (opts.open !== false) {
|
|
73794
|
+
const { default: openUrl } = await import("open");
|
|
73795
|
+
await openUrl(handle.url).catch(() => {
|
|
73796
|
+
return;
|
|
73797
|
+
});
|
|
73798
|
+
}
|
|
73799
|
+
await new Promise((done) => {
|
|
73800
|
+
const stop = () => {
|
|
73801
|
+
handle.close().finally(() => done());
|
|
73802
|
+
};
|
|
73803
|
+
process.once("SIGINT", stop);
|
|
73804
|
+
process.once("SIGTERM", stop);
|
|
73805
|
+
});
|
|
73806
|
+
return 0;
|
|
73807
|
+
}
|
|
73808
|
+
|
|
73809
|
+
// src/commands/mcp.ts
|
|
73810
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
73811
|
+
import { resolve as resolve11 } from "node:path";
|
|
73812
|
+
|
|
73813
|
+
// src/util/version.ts
|
|
73814
|
+
import { readFileSync as readFileSync34 } from "node:fs";
|
|
73815
|
+
import { dirname as dirname6, resolve as resolve10 } from "node:path";
|
|
73816
|
+
import { fileURLToPath } from "node:url";
|
|
73817
|
+
function getPackageVersion() {
|
|
73818
|
+
try {
|
|
73819
|
+
const here = dirname6(fileURLToPath(import.meta.url));
|
|
73820
|
+
for (const up of ["..", "../..", "../../.."]) {
|
|
73821
|
+
try {
|
|
73822
|
+
const pkgPath = resolve10(here, up, "package.json");
|
|
73823
|
+
const raw = readFileSync34(pkgPath, "utf8");
|
|
73824
|
+
const parsed = JSON.parse(raw);
|
|
73825
|
+
if (parsed.name === "@decocms/parity" && typeof parsed.version === "string") {
|
|
73826
|
+
return parsed.version;
|
|
73827
|
+
}
|
|
73828
|
+
} catch {}
|
|
73829
|
+
}
|
|
73830
|
+
} catch {}
|
|
73831
|
+
return "0.0.0";
|
|
73832
|
+
}
|
|
73833
|
+
|
|
73834
|
+
// src/mcp/rpc.ts
|
|
73835
|
+
var MCP_PROTOCOL_VERSION = "2024-11-05";
|
|
73836
|
+
var RpcError = {
|
|
73837
|
+
parse: -32700,
|
|
73838
|
+
invalidRequest: -32600,
|
|
73839
|
+
methodNotFound: -32601,
|
|
73840
|
+
invalidParams: -32602,
|
|
73841
|
+
internal: -32603
|
|
73842
|
+
};
|
|
73843
|
+
var ok = (text) => ({ content: [{ type: "text", text }] });
|
|
73844
|
+
var fail2 = (text) => ({
|
|
73845
|
+
content: [{ type: "text", text }],
|
|
73846
|
+
isError: true
|
|
73847
|
+
});
|
|
73848
|
+
var json = (value) => ok(JSON.stringify(value, null, 2));
|
|
73849
|
+
async function dispatch(req, opts) {
|
|
73850
|
+
const isNotification = req.id === undefined;
|
|
73851
|
+
const id = req.id ?? null;
|
|
73852
|
+
const reply = (result) => isNotification ? null : { jsonrpc: "2.0", id, result };
|
|
73853
|
+
const error = (code, message) => isNotification ? null : { jsonrpc: "2.0", id, error: { code, message } };
|
|
73854
|
+
switch (req.method) {
|
|
73855
|
+
case "initialize":
|
|
73856
|
+
return reply({
|
|
73857
|
+
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
73858
|
+
capabilities: { tools: {} },
|
|
73859
|
+
serverInfo: opts.serverInfo
|
|
73860
|
+
});
|
|
73861
|
+
case "notifications/initialized":
|
|
73862
|
+
case "initialized":
|
|
73863
|
+
return null;
|
|
73864
|
+
case "ping":
|
|
73865
|
+
return reply({});
|
|
73866
|
+
case "tools/list":
|
|
73867
|
+
return reply({
|
|
73868
|
+
tools: opts.tools.map((t) => ({
|
|
73869
|
+
name: t.name,
|
|
73870
|
+
description: t.description,
|
|
73871
|
+
inputSchema: t.inputSchema
|
|
73872
|
+
}))
|
|
73873
|
+
});
|
|
73874
|
+
case "tools/call": {
|
|
73875
|
+
const name = typeof req.params?.name === "string" ? req.params.name : null;
|
|
73876
|
+
if (!name)
|
|
73877
|
+
return error(RpcError.invalidParams, "tools/call requires params.name");
|
|
73878
|
+
const tool = opts.tools.find((t) => t.name === name);
|
|
73879
|
+
if (!tool)
|
|
73880
|
+
return error(RpcError.invalidParams, `unknown tool: ${name}`);
|
|
73881
|
+
if (tool.writes && !opts.allowWrites) {
|
|
73882
|
+
return reply(fail2(`${name} mutates the migration plan and this server is read-only. Restart it with --allow-writes.`));
|
|
73883
|
+
}
|
|
73884
|
+
const args = typeof req.params?.arguments === "object" && req.params.arguments !== null ? req.params.arguments : {};
|
|
73885
|
+
try {
|
|
73886
|
+
return reply(await tool.handler(args));
|
|
73887
|
+
} catch (err) {
|
|
73888
|
+
return reply(fail2(`${name} failed: ${err.message}`));
|
|
73889
|
+
}
|
|
73890
|
+
}
|
|
73891
|
+
default:
|
|
73892
|
+
return error(RpcError.methodNotFound, `method not found: ${req.method}`);
|
|
73893
|
+
}
|
|
73894
|
+
}
|
|
73895
|
+
function parseLine(line) {
|
|
73896
|
+
const trimmed = line.trim();
|
|
73897
|
+
if (!trimmed)
|
|
73898
|
+
return null;
|
|
73899
|
+
let parsed;
|
|
73900
|
+
try {
|
|
73901
|
+
parsed = JSON.parse(trimmed);
|
|
73902
|
+
} catch {
|
|
73903
|
+
return {
|
|
73904
|
+
res: {
|
|
73905
|
+
jsonrpc: "2.0",
|
|
73906
|
+
id: null,
|
|
73907
|
+
error: { code: RpcError.parse, message: "invalid JSON" }
|
|
73908
|
+
}
|
|
73909
|
+
};
|
|
73910
|
+
}
|
|
73911
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
73912
|
+
return {
|
|
73913
|
+
res: {
|
|
73914
|
+
jsonrpc: "2.0",
|
|
73915
|
+
id: null,
|
|
73916
|
+
error: { code: RpcError.invalidRequest, message: "expected a JSON-RPC object" }
|
|
73917
|
+
}
|
|
73918
|
+
};
|
|
73919
|
+
}
|
|
73920
|
+
const obj = parsed;
|
|
73921
|
+
if (typeof obj.method !== "string") {
|
|
73922
|
+
return {
|
|
73923
|
+
res: {
|
|
73924
|
+
jsonrpc: "2.0",
|
|
73925
|
+
id: obj.id ?? null,
|
|
73926
|
+
error: { code: RpcError.invalidRequest, message: "missing method" }
|
|
73927
|
+
}
|
|
73928
|
+
};
|
|
73929
|
+
}
|
|
73930
|
+
return { req: obj };
|
|
73931
|
+
}
|
|
73932
|
+
|
|
73933
|
+
// src/mcp/tools.ts
|
|
73934
|
+
import { existsSync as existsSync30, readFileSync as readFileSync35 } from "node:fs";
|
|
73935
|
+
import { join as join40 } from "node:path";
|
|
73936
|
+
var STR = { type: "string" };
|
|
73937
|
+
var NONE = { type: "object", properties: {}, additionalProperties: false };
|
|
73938
|
+
function withPlan2(ctx, fn) {
|
|
73939
|
+
const plan = loadPlan(ctx.planDir);
|
|
73940
|
+
if (!plan) {
|
|
73941
|
+
return {
|
|
73942
|
+
missing: `no migration-plan.json in ${ctx.planDir}. Run \`parity migrate --url <prod>\` first — without a plan there is no inventory, and a survey without one silently reports zero missing components.`
|
|
73943
|
+
};
|
|
73944
|
+
}
|
|
73945
|
+
return fn(plan);
|
|
73946
|
+
}
|
|
73947
|
+
var planOrFail = (ctx, fn) => {
|
|
73948
|
+
const out = withPlan2(ctx, fn);
|
|
73949
|
+
if (out && typeof out === "object" && "missing" in out)
|
|
73950
|
+
return fail2(String(out.missing));
|
|
73951
|
+
return json(out);
|
|
73952
|
+
};
|
|
73953
|
+
function mutate(ctx, fn) {
|
|
73954
|
+
const plan = loadPlan(ctx.planDir);
|
|
73955
|
+
if (!plan)
|
|
73956
|
+
return fail2(`no migration-plan.json in ${ctx.planDir}`);
|
|
73957
|
+
const message = fn(plan);
|
|
73958
|
+
if (message === null)
|
|
73959
|
+
return fail2("no matching row in the plan");
|
|
73960
|
+
savePlan(ctx.planDir, plan);
|
|
73961
|
+
return ok(message);
|
|
73962
|
+
}
|
|
73963
|
+
var str = (args, key) => typeof args[key] === "string" && args[key] ? args[key] : null;
|
|
73964
|
+
function createTools(ctx) {
|
|
73965
|
+
return [
|
|
73966
|
+
{
|
|
73967
|
+
name: "MIGRATION_STATE",
|
|
73968
|
+
description: "The orchestrator's own state: phase, stage, round, current page, score and trend, budget. Read this first — it says what the run is doing and what it is allowed to care about.",
|
|
73969
|
+
inputSchema: NONE,
|
|
73970
|
+
handler: () => {
|
|
73971
|
+
const p = join40(ctx.planDir, "migration.json");
|
|
73972
|
+
if (!existsSync30(p)) {
|
|
73973
|
+
return fail2(`no migration.json in ${ctx.planDir} — no migration has been started here`);
|
|
73974
|
+
}
|
|
73975
|
+
try {
|
|
73976
|
+
return json(JSON.parse(readFileSync35(p, "utf8")));
|
|
73977
|
+
} catch (err) {
|
|
73978
|
+
return fail2(`migration.json is not valid JSON: ${err.message}`);
|
|
73979
|
+
}
|
|
73980
|
+
}
|
|
73981
|
+
},
|
|
73982
|
+
{
|
|
73983
|
+
name: "PLAN_STATUS",
|
|
73984
|
+
description: "The inventory: components settled vs remaining, pages awaiting content, plus the two run-level numbers — reuse (library vs written here) and human touches. `as-is` and `upgrade` are reported apart from settled, because 'we tolerated a difference' and 'we did it better' are the two lines a stakeholder asks about and both look identical to a visual diff.",
|
|
73985
|
+
inputSchema: NONE,
|
|
73986
|
+
handler: () => planOrFail(ctx, (plan) => ({
|
|
73987
|
+
url: plan.url,
|
|
73988
|
+
target: plan.target.name,
|
|
73989
|
+
...planProgress(plan),
|
|
73990
|
+
provenance: provenanceCounts(plan),
|
|
73991
|
+
touches: totalTouches(plan)
|
|
73992
|
+
}))
|
|
73993
|
+
},
|
|
73994
|
+
{
|
|
73995
|
+
name: "PLAN_BOARD",
|
|
73996
|
+
description: "Every sampled page in a lane (triage/backlog/building/review/done) with what blocks it, plus `shell` (globals, which block every page) and `no page` (components no sampled page uses). Lanes are DERIVED from the page's components, so a page cannot read as done while something it needs is missing.",
|
|
73997
|
+
inputSchema: {
|
|
73998
|
+
type: "object",
|
|
73999
|
+
properties: { candUrl: STR },
|
|
74000
|
+
additionalProperties: false
|
|
74001
|
+
},
|
|
74002
|
+
handler: (args) => planOrFail(ctx, (plan) => planBoard(plan, str(args, "candUrl") ?? ctx.candUrl))
|
|
74003
|
+
},
|
|
74004
|
+
{
|
|
74005
|
+
name: "PAGE_WORKSHEET",
|
|
74006
|
+
description: "One page's components grouped by what to do about them (build | validate | upgrade | as-is | settled), each with a runnable command. `ready: true` means nothing is left to build or validate. Note that GLOBAL components (header, footer, nav) are not page members in the capture, so they never appear here — settle them first or a global fix reopens closed pages.",
|
|
74007
|
+
inputSchema: {
|
|
74008
|
+
type: "object",
|
|
74009
|
+
properties: { path: STR, candUrl: STR },
|
|
74010
|
+
required: ["path"],
|
|
74011
|
+
additionalProperties: false
|
|
74012
|
+
},
|
|
74013
|
+
handler: (args) => {
|
|
74014
|
+
const path = str(args, "path");
|
|
74015
|
+
if (!path)
|
|
74016
|
+
return fail2("path is required");
|
|
74017
|
+
const out = withPlan2(ctx, (plan) => pagePlan(plan, path, str(args, "candUrl") ?? ctx.candUrl));
|
|
74018
|
+
if (out && typeof out === "object" && "missing" in out)
|
|
74019
|
+
return fail2(String(out.missing));
|
|
74020
|
+
if (out === null)
|
|
74021
|
+
return fail2(`the plan has no page at ${path}`);
|
|
74022
|
+
return json(out);
|
|
74023
|
+
}
|
|
74024
|
+
},
|
|
74025
|
+
{
|
|
74026
|
+
name: "RUN_LIST",
|
|
74027
|
+
description: "Saved parity runs, newest first: id, timestamp, report path.",
|
|
74028
|
+
inputSchema: {
|
|
74029
|
+
type: "object",
|
|
74030
|
+
properties: { limit: { type: "number" } },
|
|
74031
|
+
additionalProperties: false
|
|
74032
|
+
},
|
|
74033
|
+
handler: (args) => {
|
|
74034
|
+
const limit = typeof args.limit === "number" ? args.limit : 20;
|
|
74035
|
+
return json(listRuns(ctx.output).slice(0, limit));
|
|
74036
|
+
}
|
|
74037
|
+
},
|
|
74038
|
+
{
|
|
74039
|
+
name: "RUN_REPORT",
|
|
74040
|
+
description: "One run's verdict, top issues and per-check results — the score with its receipts. Pass no id for the most recent run.",
|
|
74041
|
+
inputSchema: {
|
|
74042
|
+
type: "object",
|
|
74043
|
+
properties: { runId: STR },
|
|
74044
|
+
additionalProperties: false
|
|
74045
|
+
},
|
|
74046
|
+
handler: (args) => {
|
|
74047
|
+
const id = str(args, "runId") ?? listRuns(ctx.output)[0]?.id;
|
|
74048
|
+
if (!id)
|
|
74049
|
+
return fail2(`no runs found under ${ctx.output}`);
|
|
74050
|
+
try {
|
|
74051
|
+
const run = loadRun(ctx.output, id);
|
|
74052
|
+
return json({
|
|
74053
|
+
id: run.id,
|
|
74054
|
+
timestamp: run.timestamp,
|
|
74055
|
+
prodUrl: run.prodUrl,
|
|
74056
|
+
candUrl: run.candUrl,
|
|
74057
|
+
verdict: run.verdict,
|
|
74058
|
+
previousRun: run.previousRun ?? null,
|
|
74059
|
+
topIssues: run.topIssues,
|
|
74060
|
+
checks: run.checks.map((c) => ({
|
|
74061
|
+
name: c.name,
|
|
74062
|
+
status: c.status,
|
|
74063
|
+
severity: c.severity,
|
|
74064
|
+
summary: c.summary,
|
|
74065
|
+
issues: c.issues.length
|
|
74066
|
+
}))
|
|
74067
|
+
});
|
|
74068
|
+
} catch (err) {
|
|
74069
|
+
return fail2(err.message);
|
|
74070
|
+
}
|
|
74071
|
+
}
|
|
74072
|
+
},
|
|
74073
|
+
{
|
|
74074
|
+
name: "SET_STATUS",
|
|
74075
|
+
description: "Flip a component's porting status: pending | partial | done | as-is | upgrade | skipped. `as-is` and `upgrade` mean 'stop opening work for this' and are the USER's call — an agent setting them itself is how a real gap disappears from view.",
|
|
74076
|
+
inputSchema: {
|
|
74077
|
+
type: "object",
|
|
74078
|
+
properties: { name: STR, status: STR },
|
|
74079
|
+
required: ["name", "status"],
|
|
74080
|
+
additionalProperties: false
|
|
74081
|
+
},
|
|
74082
|
+
writes: true,
|
|
74083
|
+
handler: (args) => {
|
|
74084
|
+
const name = str(args, "name");
|
|
74085
|
+
const status = str(args, "status");
|
|
74086
|
+
if (!name || !status)
|
|
74087
|
+
return fail2("name and status are required");
|
|
74088
|
+
const allowed = ["pending", "partial", "done", "as-is", "upgrade", "skipped"];
|
|
74089
|
+
if (!allowed.includes(status)) {
|
|
74090
|
+
return fail2(`invalid status "${status}". Use one of: ${allowed.join(", ")}`);
|
|
74091
|
+
}
|
|
74092
|
+
return mutate(ctx, (plan) => {
|
|
74093
|
+
const c = setComponentStatus(plan, name, status);
|
|
74094
|
+
return c ? `${c.name} → ${status}` : null;
|
|
74095
|
+
});
|
|
74096
|
+
}
|
|
74097
|
+
},
|
|
74098
|
+
{
|
|
74099
|
+
name: "SET_PAGE_STATUS",
|
|
74100
|
+
description: "Flip a page's readiness: pending (no route yet) | code (route + sections exist but the CMS has nothing published, so it renders empty — the most common real state) | done (code AND content) | skipped.",
|
|
74101
|
+
inputSchema: {
|
|
74102
|
+
type: "object",
|
|
74103
|
+
properties: { path: STR, status: STR },
|
|
74104
|
+
required: ["path", "status"],
|
|
74105
|
+
additionalProperties: false
|
|
74106
|
+
},
|
|
74107
|
+
writes: true,
|
|
74108
|
+
handler: (args) => {
|
|
74109
|
+
const path = str(args, "path");
|
|
74110
|
+
const status = str(args, "status");
|
|
74111
|
+
if (!path || !status)
|
|
74112
|
+
return fail2("path and status are required");
|
|
74113
|
+
const allowed = ["pending", "code", "done", "skipped"];
|
|
74114
|
+
if (!allowed.includes(status)) {
|
|
74115
|
+
return fail2(`invalid status "${status}". Use one of: ${allowed.join(", ")}`);
|
|
74116
|
+
}
|
|
74117
|
+
return mutate(ctx, (plan) => {
|
|
74118
|
+
const p = setPageStatus(plan, path, status);
|
|
74119
|
+
return p ? `${p.path} → ${status}` : null;
|
|
74120
|
+
});
|
|
74121
|
+
}
|
|
74122
|
+
},
|
|
74123
|
+
{
|
|
74124
|
+
name: "SET_PROVENANCE",
|
|
74125
|
+
description: "Record where a shipped component came from: `library` (reused from the shared target template) or `built` (written for this migration). Rollouts are priced on store N costing less than store N-1, and reuse is the only mechanism that delivers that.",
|
|
74126
|
+
inputSchema: {
|
|
74127
|
+
type: "object",
|
|
74128
|
+
properties: { name: STR, provenance: STR },
|
|
74129
|
+
required: ["name", "provenance"],
|
|
74130
|
+
additionalProperties: false
|
|
74131
|
+
},
|
|
74132
|
+
writes: true,
|
|
74133
|
+
handler: (args) => {
|
|
74134
|
+
const name = str(args, "name");
|
|
74135
|
+
const provenance = str(args, "provenance");
|
|
74136
|
+
if (!name || provenance !== "library" && provenance !== "built") {
|
|
74137
|
+
return fail2("name is required and provenance must be `library` or `built`");
|
|
74138
|
+
}
|
|
74139
|
+
return mutate(ctx, (plan) => {
|
|
74140
|
+
const c = setComponentProvenance(plan, name, provenance);
|
|
74141
|
+
return c ? `${c.name} → ${provenance}` : null;
|
|
74142
|
+
});
|
|
74143
|
+
}
|
|
74144
|
+
},
|
|
74145
|
+
{
|
|
74146
|
+
name: "TOUCH",
|
|
74147
|
+
description: "Count one occasion where a PERSON pointed at a defect the tooling did not surface. This is the metric that says whether the loop is converging — one real page took fourteen. Do not call it for the tool's own findings; padding it destroys the signal it carries.",
|
|
74148
|
+
inputSchema: {
|
|
74149
|
+
type: "object",
|
|
74150
|
+
properties: { page: STR },
|
|
74151
|
+
required: ["page"],
|
|
74152
|
+
additionalProperties: false
|
|
74153
|
+
},
|
|
74154
|
+
writes: true,
|
|
74155
|
+
handler: (args) => {
|
|
74156
|
+
const page = str(args, "page");
|
|
74157
|
+
if (!page)
|
|
74158
|
+
return fail2("page is required");
|
|
74159
|
+
return mutate(ctx, (plan) => {
|
|
74160
|
+
const n = recordTouch(plan, page);
|
|
74161
|
+
return `${page} → ${n} human touch(es); ${totalTouches(plan)} in this migration`;
|
|
74162
|
+
});
|
|
74163
|
+
}
|
|
74164
|
+
}
|
|
74165
|
+
];
|
|
74166
|
+
}
|
|
74167
|
+
|
|
74168
|
+
// src/commands/mcp.ts
|
|
74169
|
+
async function mcpCommand(opts) {
|
|
74170
|
+
const version = getPackageVersion();
|
|
74171
|
+
const tools = createTools({
|
|
74172
|
+
planDir: resolve11(opts.dir),
|
|
74173
|
+
output: resolve11(opts.output),
|
|
74174
|
+
candUrl: opts.candUrl
|
|
74175
|
+
});
|
|
74176
|
+
const write = (res) => process.stdout.write(`${JSON.stringify(res)}
|
|
74177
|
+
`);
|
|
74178
|
+
process.stderr.write(`parity mcp ${version} — ${tools.length} tools, ${opts.allowWrites ? "writes ALLOWED" : "read-only"}
|
|
74179
|
+
`);
|
|
74180
|
+
const rl = createInterface3({ input: process.stdin, crlfDelay: Number.POSITIVE_INFINITY });
|
|
74181
|
+
let queue = Promise.resolve();
|
|
74182
|
+
for await (const line of rl) {
|
|
74183
|
+
const parsed = parseLine(line);
|
|
74184
|
+
if (!parsed)
|
|
74185
|
+
continue;
|
|
74186
|
+
if ("res" in parsed) {
|
|
74187
|
+
write(parsed.res);
|
|
74188
|
+
continue;
|
|
74189
|
+
}
|
|
74190
|
+
const req = parsed.req;
|
|
74191
|
+
queue = queue.then(async () => {
|
|
74192
|
+
const res = await dispatch(req, {
|
|
74193
|
+
tools,
|
|
74194
|
+
serverInfo: { name: "parity", version },
|
|
74195
|
+
allowWrites: Boolean(opts.allowWrites)
|
|
74196
|
+
});
|
|
74197
|
+
if (res)
|
|
74198
|
+
write(res);
|
|
74199
|
+
});
|
|
74200
|
+
}
|
|
74201
|
+
await queue;
|
|
74202
|
+
return 0;
|
|
74203
|
+
}
|
|
74204
|
+
|
|
74205
|
+
// src/commands/states.ts
|
|
74206
|
+
import chalk30 from "chalk";
|
|
72182
74207
|
var HOVERABLE = "a,button,summary,[role='button'],[role='menuitem'],label";
|
|
72183
|
-
|
|
74208
|
+
var SETTLE_RETRY_FACTOR = 4;
|
|
74209
|
+
async function readStateEffects(page, opts) {
|
|
74210
|
+
const { selector, base, max, settleMs } = opts;
|
|
74211
|
+
await page.waitForTimeout(settleMs);
|
|
74212
|
+
const control = await readDelta(page, selector, base);
|
|
74213
|
+
const ambient = new Set((control?.deltas ?? []).map((d) => `${d.key}\x00${d.prop}`));
|
|
72184
74214
|
const root = page.locator(selector).first();
|
|
72185
74215
|
const targets = root.locator(HOVERABLE);
|
|
72186
74216
|
const total = await targets.count().catch(() => 0);
|
|
@@ -72188,61 +74218,123 @@ async function readStateEffects(page, selector, base, max) {
|
|
|
72188
74218
|
const effects = [];
|
|
72189
74219
|
for (let i = 0;i < take; i++) {
|
|
72190
74220
|
const el = targets.nth(i);
|
|
72191
|
-
const meta = await el.evaluate((node) => {
|
|
74221
|
+
const meta = await el.evaluate((node, sel) => {
|
|
74222
|
+
const root = document.querySelector(sel);
|
|
72192
74223
|
const parts = [];
|
|
72193
74224
|
let cur = node;
|
|
72194
|
-
while (cur
|
|
74225
|
+
while (cur && cur !== root) {
|
|
74226
|
+
const parent = cur.parentElement;
|
|
74227
|
+
if (!parent)
|
|
74228
|
+
break;
|
|
72195
74229
|
const t = cur.tagName.toLowerCase();
|
|
72196
74230
|
let idx = 0;
|
|
72197
|
-
for (const sib of Array.from(
|
|
74231
|
+
for (const sib of Array.from(parent.children)) {
|
|
72198
74232
|
if (sib === cur)
|
|
72199
74233
|
break;
|
|
72200
74234
|
if (sib.tagName.toLowerCase() === t)
|
|
72201
74235
|
idx++;
|
|
72202
74236
|
}
|
|
72203
74237
|
parts.unshift(`${t}[${idx}]`);
|
|
72204
|
-
cur =
|
|
74238
|
+
cur = parent;
|
|
72205
74239
|
}
|
|
74240
|
+
const rootTag = root?.tagName.toLowerCase();
|
|
72206
74241
|
return {
|
|
72207
|
-
path: parts.join(">"),
|
|
74242
|
+
path: rootTag ? [rootTag, ...parts].join(">") : parts.join(">"),
|
|
72208
74243
|
label: node.getAttribute("data-testid") ?? node.getAttribute("aria-label") ?? ((node.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 30) || null)
|
|
72209
74244
|
};
|
|
72210
|
-
}).catch(() => null);
|
|
74245
|
+
}, opts.selector).catch(() => null);
|
|
72211
74246
|
if (!meta)
|
|
72212
74247
|
continue;
|
|
72213
74248
|
const hovered = await el.hover({ timeout: 2000 }).then(() => true).catch(() => false);
|
|
72214
74249
|
if (!hovered)
|
|
72215
74250
|
continue;
|
|
72216
|
-
await page.waitForTimeout(
|
|
72217
|
-
|
|
74251
|
+
await page.waitForTimeout(settleMs);
|
|
74252
|
+
let delta = await readDelta(page, selector, base);
|
|
74253
|
+
if (delta && delta.deltas.length === 0) {
|
|
74254
|
+
await page.waitForTimeout(settleMs * SETTLE_RETRY_FACTOR);
|
|
74255
|
+
delta = await readDelta(page, selector, base);
|
|
74256
|
+
}
|
|
72218
74257
|
await page.mouse.move(0, 0).catch(() => {
|
|
72219
74258
|
return;
|
|
72220
74259
|
});
|
|
72221
|
-
if (!
|
|
74260
|
+
if (!delta)
|
|
72222
74261
|
continue;
|
|
72223
|
-
const
|
|
72224
|
-
|
|
74262
|
+
const attributable = delta.deltas.filter((d) => !ambient.has(`${d.key}\x00${d.prop}`));
|
|
74263
|
+
const changes = attributable.map((d) => ({
|
|
74264
|
+
node: d.key,
|
|
74265
|
+
prop: d.prop,
|
|
74266
|
+
comparable: d.key === meta.path || delta.stable(d.key)
|
|
74267
|
+
}));
|
|
74268
|
+
if (changes.length === 0) {
|
|
74269
|
+
effects.push({
|
|
74270
|
+
target: meta.path,
|
|
74271
|
+
label: meta.label,
|
|
74272
|
+
changedProps: 0,
|
|
74273
|
+
properties: [],
|
|
74274
|
+
changes: [],
|
|
74275
|
+
renumberedNodes: 0
|
|
74276
|
+
});
|
|
72225
74277
|
continue;
|
|
74278
|
+
}
|
|
72226
74279
|
effects.push({
|
|
72227
74280
|
target: meta.path,
|
|
72228
74281
|
label: meta.label,
|
|
72229
|
-
changedProps:
|
|
72230
|
-
properties: [...new Set(
|
|
74282
|
+
changedProps: changes.length,
|
|
74283
|
+
properties: [...new Set(changes.map((c) => c.prop))].sort(),
|
|
74284
|
+
changes,
|
|
74285
|
+
renumberedNodes: delta.renumbered
|
|
72231
74286
|
});
|
|
72232
74287
|
}
|
|
72233
|
-
return { effects, truncated: total > take };
|
|
74288
|
+
return { effects, truncated: total > take, ambient: ambient.size };
|
|
74289
|
+
}
|
|
74290
|
+
var fingerprint = (n) => `${n.tag}\x00${n.label ?? ""}\x00${n.text ?? ""}`;
|
|
74291
|
+
async function readDelta(page, selector, base) {
|
|
74292
|
+
const after = await readBoxTree(page, selector);
|
|
74293
|
+
if (!after.found)
|
|
74294
|
+
return null;
|
|
74295
|
+
const diff = diffBoxTrees(base, after.nodes, { tolerancePx: 0 });
|
|
74296
|
+
const beforeAt = new Map(base.map((n) => [n.key, fingerprint(n)]));
|
|
74297
|
+
const afterAt = new Map(after.nodes.map((n) => [n.key, fingerprint(n)]));
|
|
74298
|
+
const stable = (key) => {
|
|
74299
|
+
const b = beforeAt.get(key);
|
|
74300
|
+
const a = afterAt.get(key);
|
|
74301
|
+
return b !== undefined && a !== undefined && b === a;
|
|
74302
|
+
};
|
|
74303
|
+
return {
|
|
74304
|
+
deltas: diff.deltas,
|
|
74305
|
+
stable,
|
|
74306
|
+
renumbered: diff.deltas.filter((d) => !stable(d.key)).length,
|
|
74307
|
+
truncated: after.truncated
|
|
74308
|
+
};
|
|
72234
74309
|
}
|
|
72235
74310
|
async function gatherStates(browser, opts) {
|
|
72236
74311
|
const ctx = await newContext(browser, { viewport: opts.viewport });
|
|
72237
74312
|
const page = await ctx.newPage();
|
|
72238
|
-
const out = {
|
|
74313
|
+
const out = {
|
|
74314
|
+
motion: { found: false, error: "not read" },
|
|
74315
|
+
base: null,
|
|
74316
|
+
effects: [],
|
|
74317
|
+
truncated: false,
|
|
74318
|
+
ambient: 0
|
|
74319
|
+
};
|
|
72239
74320
|
try {
|
|
72240
|
-
await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 });
|
|
74321
|
+
const res = await page.goto(opts.url, { waitUntil: "domcontentloaded", timeout: 30000 }).catch((err) => err);
|
|
74322
|
+
if (res instanceof Error) {
|
|
74323
|
+
out.baseError = `${opts.url} não respondeu — ${res.message.split(`
|
|
74324
|
+
`)[0]}`;
|
|
74325
|
+
return out;
|
|
74326
|
+
}
|
|
74327
|
+
if (res && res.status() >= 400) {
|
|
74328
|
+
out.baseError = `${opts.url} respondeu HTTP ${res.status()}`;
|
|
74329
|
+
return out;
|
|
74330
|
+
}
|
|
72241
74331
|
await page.waitForLoadState("networkidle", { timeout: 8000 }).catch(() => {
|
|
72242
74332
|
return;
|
|
72243
74333
|
});
|
|
72244
74334
|
if (opts.waitMs > 0)
|
|
72245
74335
|
await page.waitForTimeout(opts.waitMs);
|
|
74336
|
+
await reloadIfOptionalFonts(page, opts.waitMs);
|
|
74337
|
+
out.settle = await waitForLayoutStable(page);
|
|
72246
74338
|
await Promise.race([
|
|
72247
74339
|
stabilizeCarousels(page).catch(() => {
|
|
72248
74340
|
return;
|
|
@@ -72256,8 +74348,14 @@ async function gatherStates(browser, opts) {
|
|
|
72256
74348
|
return out;
|
|
72257
74349
|
}
|
|
72258
74350
|
out.base = base.nodes;
|
|
72259
|
-
const { effects, truncated } = await readStateEffects(page,
|
|
74351
|
+
const { effects, truncated, ambient } = await readStateEffects(page, {
|
|
74352
|
+
selector: opts.selector,
|
|
74353
|
+
base: base.nodes,
|
|
74354
|
+
max: opts.maxStates,
|
|
74355
|
+
settleMs: opts.settleMs
|
|
74356
|
+
});
|
|
72260
74357
|
out.effects = effects;
|
|
74358
|
+
out.ambient = ambient;
|
|
72261
74359
|
out.truncated = truncated || base.truncated;
|
|
72262
74360
|
} finally {
|
|
72263
74361
|
await page.close().catch(() => {
|
|
@@ -72271,50 +74369,117 @@ async function gatherStates(browser, opts) {
|
|
|
72271
74369
|
}
|
|
72272
74370
|
function diffEffects(prod, cand) {
|
|
72273
74371
|
const byTarget = new Map(cand.map((e) => [e.target, e]));
|
|
74372
|
+
const labelSeen = new Map;
|
|
74373
|
+
for (const c of cand) {
|
|
74374
|
+
if (!c.label)
|
|
74375
|
+
continue;
|
|
74376
|
+
labelSeen.set(c.label, labelSeen.has(c.label) ? null : c);
|
|
74377
|
+
}
|
|
74378
|
+
const byLabel = new Map;
|
|
74379
|
+
for (const [k, v] of labelSeen)
|
|
74380
|
+
if (v)
|
|
74381
|
+
byLabel.set(k, v);
|
|
72274
74382
|
const lost = [];
|
|
74383
|
+
const unpaired = [];
|
|
72275
74384
|
const changed = [];
|
|
72276
|
-
const
|
|
74385
|
+
const used = new Set;
|
|
72277
74386
|
for (const p of prod) {
|
|
72278
|
-
|
|
72279
|
-
|
|
74387
|
+
if (p.properties.length === 0)
|
|
74388
|
+
continue;
|
|
74389
|
+
const c = byTarget.get(p.target) ?? (p.label ? byLabel.get(p.label) : undefined);
|
|
74390
|
+
if (!c || used.has(c)) {
|
|
74391
|
+
unpaired.push(p);
|
|
74392
|
+
continue;
|
|
74393
|
+
}
|
|
74394
|
+
used.add(c);
|
|
74395
|
+
if (c.properties.length === 0) {
|
|
72280
74396
|
lost.push(p);
|
|
72281
74397
|
continue;
|
|
72282
74398
|
}
|
|
72283
|
-
|
|
72284
|
-
|
|
72285
|
-
|
|
74399
|
+
const missing = p.properties.filter((x) => !c.properties.includes(x));
|
|
74400
|
+
const extra = c.properties.filter((x) => !p.properties.includes(x));
|
|
74401
|
+
if (missing.length === 0 && extra.length === 0)
|
|
74402
|
+
continue;
|
|
74403
|
+
const comparableProps = new Set(p.changes.filter((ch) => ch.comparable).map((ch) => ch.prop));
|
|
74404
|
+
changed.push({
|
|
74405
|
+
prod: p,
|
|
74406
|
+
cand: c,
|
|
74407
|
+
missing,
|
|
74408
|
+
extra,
|
|
74409
|
+
notComparable: missing.filter((x) => !comparableProps.has(x)),
|
|
74410
|
+
onElement: missing.filter((x) => comparableProps.has(x))
|
|
74411
|
+
});
|
|
72286
74412
|
}
|
|
72287
|
-
return {
|
|
74413
|
+
return {
|
|
74414
|
+
lost,
|
|
74415
|
+
unpaired,
|
|
74416
|
+
added: cand.filter((c) => !used.has(c) && c.properties.length > 0),
|
|
74417
|
+
changed
|
|
74418
|
+
};
|
|
74419
|
+
}
|
|
74420
|
+
function statesVerdict(counts) {
|
|
74421
|
+
const exercised = counts.prodEffects > 0 || counts.candEffects > 0;
|
|
74422
|
+
return { exercised, inconclusive: !exercised && counts.motionMatched === 0 };
|
|
72288
74423
|
}
|
|
72289
74424
|
async function statesCommand(opts) {
|
|
72290
74425
|
const viewport = parseViewport3(opts.viewport);
|
|
72291
74426
|
if (!viewport) {
|
|
72292
|
-
console.error(
|
|
74427
|
+
console.error(chalk30.red(`--viewport inválido: ${opts.viewport}`));
|
|
72293
74428
|
return 2;
|
|
72294
74429
|
}
|
|
72295
74430
|
const waitMs = Number.parseInt(opts.wait, 10) || 0;
|
|
72296
74431
|
const maxStates = Math.max(1, Number.parseInt(opts.maxStates ?? "12", 10) || 12);
|
|
72297
|
-
const
|
|
74432
|
+
const settleMs = Math.max(0, Number.parseInt(opts.hoverSettle ?? "250", 10) || 250);
|
|
74433
|
+
const prodSelector = opts.prodSelector?.trim() || opts.selector?.trim();
|
|
74434
|
+
const candSelector = opts.candSelector?.trim() || opts.selector?.trim();
|
|
74435
|
+
if (!prodSelector || !candSelector) {
|
|
74436
|
+
console.error(chalk30.red(" informe --selector (ambos os lados) ou --prod-selector e --cand-selector"));
|
|
74437
|
+
return 2;
|
|
74438
|
+
}
|
|
74439
|
+
const { aliases, note: aliasNote } = resolveAliases(opts.planDir);
|
|
74440
|
+
if (aliasNote)
|
|
74441
|
+
console.log(chalk30.dim(` ${aliasNote}`));
|
|
72298
74442
|
const browser = await launchBrowser({ headless: true });
|
|
72299
74443
|
try {
|
|
72300
74444
|
const [prodSide, candSide] = await Promise.all([
|
|
72301
|
-
gatherStates(browser, {
|
|
72302
|
-
|
|
74445
|
+
gatherStates(browser, {
|
|
74446
|
+
url: opts.prod,
|
|
74447
|
+
selector: prodSelector,
|
|
74448
|
+
viewport,
|
|
74449
|
+
waitMs,
|
|
74450
|
+
maxStates,
|
|
74451
|
+
settleMs
|
|
74452
|
+
}),
|
|
74453
|
+
gatherStates(browser, {
|
|
74454
|
+
url: opts.cand,
|
|
74455
|
+
selector: candSelector,
|
|
74456
|
+
viewport,
|
|
74457
|
+
waitMs,
|
|
74458
|
+
maxStates,
|
|
74459
|
+
settleMs
|
|
74460
|
+
})
|
|
72303
74461
|
]);
|
|
72304
74462
|
if (prodSide.baseError || candSide.baseError) {
|
|
72305
74463
|
const which = prodSide.baseError ? `prod: ${prodSide.baseError}` : `cand: ${candSide.baseError}`;
|
|
72306
|
-
console.error(
|
|
74464
|
+
console.error(chalk30.red(` não foi possível ler o componente — ${which}`));
|
|
72307
74465
|
return 2;
|
|
72308
74466
|
}
|
|
72309
74467
|
const motion = prodSide.motion.found && candSide.motion.found ? diffMotion(prodSide.motion, candSide.motion, {
|
|
72310
|
-
truncated: prodSide.truncated || candSide.truncated
|
|
74468
|
+
truncated: prodSide.truncated || candSide.truncated,
|
|
74469
|
+
aliases
|
|
72311
74470
|
}) : null;
|
|
72312
74471
|
const effects = diffEffects(prodSide.effects, candSide.effects);
|
|
74472
|
+
const { exercised, inconclusive } = statesVerdict({
|
|
74473
|
+
prodEffects: prodSide.effects.length,
|
|
74474
|
+
candEffects: candSide.effects.length,
|
|
74475
|
+
motionMatched: motion?.matched ?? 0
|
|
74476
|
+
});
|
|
72313
74477
|
if (opts.json) {
|
|
72314
74478
|
console.log(JSON.stringify({
|
|
72315
74479
|
prod: opts.prod,
|
|
72316
74480
|
cand: opts.cand,
|
|
72317
|
-
|
|
74481
|
+
inconclusive,
|
|
74482
|
+
prodSelector,
|
|
72318
74483
|
candSelector,
|
|
72319
74484
|
viewport,
|
|
72320
74485
|
motion,
|
|
@@ -72322,38 +74487,71 @@ async function statesCommand(opts) {
|
|
|
72322
74487
|
effects,
|
|
72323
74488
|
prodEffects: prodSide.effects,
|
|
72324
74489
|
candEffects: candSide.effects,
|
|
72325
|
-
truncated: prodSide.truncated || candSide.truncated
|
|
74490
|
+
truncated: prodSide.truncated || candSide.truncated,
|
|
74491
|
+
settle: { prod: prodSide.settle, cand: candSide.settle }
|
|
72326
74492
|
}));
|
|
72327
|
-
return effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
74493
|
+
return inconclusive || effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
74494
|
+
}
|
|
74495
|
+
for (const [name, data] of [
|
|
74496
|
+
["prod", prodSide],
|
|
74497
|
+
["cand", candSide]
|
|
74498
|
+
]) {
|
|
74499
|
+
const caveat = data.settle && formatSettleCaveat(name, data.settle);
|
|
74500
|
+
if (caveat)
|
|
74501
|
+
console.log(chalk30.yellow(` ${caveat}`));
|
|
72328
74502
|
}
|
|
72329
74503
|
console.log("");
|
|
72330
|
-
console.log(
|
|
74504
|
+
console.log(chalk30.bold(" Declared motion"));
|
|
72331
74505
|
if (!motion) {
|
|
72332
74506
|
const err = prodSide.motion.found ? candSide.motion : prodSide.motion;
|
|
72333
|
-
console.log(
|
|
74507
|
+
console.log(chalk30.yellow(` não foi possível comparar — ${"error" in err ? err.error : "?"}`));
|
|
72334
74508
|
} else {
|
|
72335
74509
|
for (const line of formatMotionDiff(motion).split(`
|
|
72336
74510
|
`))
|
|
72337
74511
|
console.log(` ${line}`);
|
|
72338
74512
|
}
|
|
72339
74513
|
console.log("");
|
|
72340
|
-
console.log(
|
|
72341
|
-
|
|
74514
|
+
console.log(chalk30.bold(` Hover effects (${prodSide.effects.length} prod / ${candSide.effects.length} cand)`));
|
|
74515
|
+
const nothing = effects.lost.length === 0 && effects.changed.length === 0 && effects.added.length === 0 && effects.unpaired.length === 0;
|
|
74516
|
+
if (nothing && !exercised) {
|
|
74517
|
+
console.log(chalk30.yellow(" INCONCLUSIVE — no hover changed anything on either side, so nothing was exercised. Check the selector holds an interactive element."));
|
|
74518
|
+
} else if (nothing) {
|
|
72342
74519
|
console.log(" clean — every hover that changes something in prod changes the same in cand");
|
|
72343
74520
|
}
|
|
72344
74521
|
for (const e of effects.lost) {
|
|
72345
|
-
console.log(
|
|
74522
|
+
console.log(chalk30.red(` LOST ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}]; cand's element was hovered and moved nothing`));
|
|
72346
74523
|
}
|
|
72347
|
-
for (const { prod,
|
|
72348
|
-
console.log(` DIFFERS
|
|
74524
|
+
for (const { prod, extra, notComparable, onElement } of effects.changed) {
|
|
74525
|
+
console.log(` DIFFERS ${prod.target}${prod.label ? ` (${prod.label})` : ""}`);
|
|
74526
|
+
if (onElement.length) {
|
|
74527
|
+
console.log(chalk30.yellow(` prod also moves [${onElement.join(", ")}] on the element itself`));
|
|
74528
|
+
}
|
|
74529
|
+
if (extra.length)
|
|
74530
|
+
console.log(` cand also moves [${extra.join(", ")}]`);
|
|
74531
|
+
if (notComparable.length) {
|
|
74532
|
+
console.log(chalk30.dim(` not comparable: [${notComparable.join(", ")}] — prod's hover renumbered ${prod.renumberedNodes} of the changed paths, so these were read on elements that are not the same ones before and after. Bench the component, or pick a selector whose subtree the hover does not restructure.`));
|
|
74533
|
+
}
|
|
74534
|
+
if (onElement.length === 0 && extra.length === 0) {
|
|
74535
|
+
console.log(chalk30.dim(" nothing comparable differs."));
|
|
74536
|
+
}
|
|
74537
|
+
}
|
|
74538
|
+
for (const e of effects.unpaired) {
|
|
74539
|
+
console.log(chalk30.dim(` UNPAIRED ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}]; no matching element found on the cand side (not a defect — the port may have changed the element, or it is outside --selector)`));
|
|
72349
74540
|
}
|
|
72350
74541
|
for (const e of effects.added) {
|
|
72351
|
-
console.log(` ADDED
|
|
74542
|
+
console.log(` ADDED ${e.target} — cand moves [${e.properties.join(", ")}]; prod does not`);
|
|
74543
|
+
}
|
|
74544
|
+
if (effects.unpaired.length > 0 && effects.lost.length === 0 && effects.changed.length === 0) {
|
|
74545
|
+
console.log("");
|
|
74546
|
+
console.log(chalk30.yellow(` ${effects.unpaired.length} prod effect(s) had no counterpart and NOTHING paired. That is a pairing failure, not a set of defects — check --selector contains the same component on both sides, and that ported roots carry data-section.`));
|
|
74547
|
+
}
|
|
74548
|
+
if (prodSide.ambient > 0 || candSide.ambient > 0) {
|
|
74549
|
+
console.log(chalk30.dim(` ${prodSide.ambient} prod / ${candSide.ambient} cand node+property pair(s) were moving with no interaction (carousel, autoplaying video, anything on a timer) and were subtracted. A large count means --selector contains something animating on its own; narrow it.`));
|
|
72352
74550
|
}
|
|
72353
74551
|
if (prodSide.truncated || candSide.truncated) {
|
|
72354
|
-
console.log(
|
|
74552
|
+
console.log(chalk30.dim(" TRUNCATED — element cap hit; absence of a finding is not proof"));
|
|
72355
74553
|
}
|
|
72356
|
-
return effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
74554
|
+
return inconclusive || effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
72357
74555
|
} finally {
|
|
72358
74556
|
await browser.close().catch(() => {
|
|
72359
74557
|
return;
|
|
@@ -72361,11 +74559,145 @@ async function statesCommand(opts) {
|
|
|
72361
74559
|
}
|
|
72362
74560
|
}
|
|
72363
74561
|
|
|
74562
|
+
// src/commands/variance.ts
|
|
74563
|
+
import chalk31 from "chalk";
|
|
74564
|
+
|
|
74565
|
+
// src/diff/variance.ts
|
|
74566
|
+
var uniq2 = (xs) => [...new Set(xs)];
|
|
74567
|
+
var host = (url) => {
|
|
74568
|
+
try {
|
|
74569
|
+
return new URL(url).host;
|
|
74570
|
+
} catch {
|
|
74571
|
+
return url;
|
|
74572
|
+
}
|
|
74573
|
+
};
|
|
74574
|
+
function computeVariance(runs) {
|
|
74575
|
+
const runIds = runs.map((r) => r.id);
|
|
74576
|
+
const base = {
|
|
74577
|
+
runIds,
|
|
74578
|
+
comparable: true,
|
|
74579
|
+
scores: runs.map((r) => r.verdict.score),
|
|
74580
|
+
scoreSpread: 0,
|
|
74581
|
+
unstable: [],
|
|
74582
|
+
inconsistentlyRun: []
|
|
74583
|
+
};
|
|
74584
|
+
if (runs.length < 2) {
|
|
74585
|
+
return {
|
|
74586
|
+
...base,
|
|
74587
|
+
comparable: false,
|
|
74588
|
+
incomparableReason: "need at least two runs to measure variance"
|
|
74589
|
+
};
|
|
74590
|
+
}
|
|
74591
|
+
const pairs = uniq2(runs.map((r) => `${host(r.prodUrl)} × ${host(r.candUrl)}`));
|
|
74592
|
+
if (pairs.length > 1) {
|
|
74593
|
+
return {
|
|
74594
|
+
...base,
|
|
74595
|
+
comparable: false,
|
|
74596
|
+
incomparableReason: `runs compare different host pairs (${pairs.join(", ")}) — that is not variance`
|
|
74597
|
+
};
|
|
74598
|
+
}
|
|
74599
|
+
const versions = uniq2(runs.map((r) => r.verdict.scoreVersion ?? 1));
|
|
74600
|
+
if (versions.length > 1) {
|
|
74601
|
+
return {
|
|
74602
|
+
...base,
|
|
74603
|
+
comparable: false,
|
|
74604
|
+
incomparableReason: `runs used different score versions (${versions.join(", ")}) — scores are not on the same scale`
|
|
74605
|
+
};
|
|
74606
|
+
}
|
|
74607
|
+
const scores = runs.map((r) => r.verdict.score);
|
|
74608
|
+
const scoreSpread = Math.round((Math.max(...scores) - Math.min(...scores)) * 100) / 100;
|
|
74609
|
+
const perRun = runs.map((r) => new Map(r.checks.map((c) => [c.name, c])));
|
|
74610
|
+
const allNames = uniq2(runs.flatMap((r) => r.checks.map((c) => c.name))).sort();
|
|
74611
|
+
const unstable = [];
|
|
74612
|
+
const inconsistentlyRun = [];
|
|
74613
|
+
for (const name of allNames) {
|
|
74614
|
+
const seen = perRun.filter((m) => m.has(name));
|
|
74615
|
+
if (seen.length !== runs.length) {
|
|
74616
|
+
inconsistentlyRun.push(name);
|
|
74617
|
+
continue;
|
|
74618
|
+
}
|
|
74619
|
+
const statuses = uniq2(seen.map((m) => m.get(name)?.status ?? "?"));
|
|
74620
|
+
const issueCounts = seen.map((m) => m.get(name)?.issues.length ?? 0);
|
|
74621
|
+
const countsDiffer = uniq2(issueCounts).length > 1;
|
|
74622
|
+
if (statuses.length > 1 || countsDiffer) {
|
|
74623
|
+
unstable.push({
|
|
74624
|
+
name,
|
|
74625
|
+
statuses,
|
|
74626
|
+
runsSeen: seen.length,
|
|
74627
|
+
issueCounts,
|
|
74628
|
+
flipsStatus: statuses.length > 1
|
|
74629
|
+
});
|
|
74630
|
+
}
|
|
74631
|
+
}
|
|
74632
|
+
unstable.sort((a, b) => Number(b.flipsStatus) - Number(a.flipsStatus) || Math.max(...b.issueCounts) - Math.min(...b.issueCounts) - (Math.max(...a.issueCounts) - Math.min(...a.issueCounts)) || a.name.localeCompare(b.name));
|
|
74633
|
+
return { ...base, scores, scoreSpread, unstable, inconsistentlyRun };
|
|
74634
|
+
}
|
|
74635
|
+
function isStable(report, scoreBudget = 1) {
|
|
74636
|
+
return report.comparable && report.scoreSpread <= scoreBudget && report.unstable.every((u) => !u.flipsStatus);
|
|
74637
|
+
}
|
|
74638
|
+
function formatVariance(report, opts = {}) {
|
|
74639
|
+
const budget = opts.scoreBudget ?? 1;
|
|
74640
|
+
if (!report.comparable) {
|
|
74641
|
+
return `variance: cannot compare — ${report.incomparableReason}`;
|
|
74642
|
+
}
|
|
74643
|
+
const lines = [
|
|
74644
|
+
`runs ${report.runIds.join(", ")}`,
|
|
74645
|
+
`scores ${report.scores.join(", ")} (spread ${report.scoreSpread}, budget ${budget})`
|
|
74646
|
+
];
|
|
74647
|
+
if (report.unstable.length === 0) {
|
|
74648
|
+
lines.push("checks every check reported identically across all runs");
|
|
74649
|
+
} else {
|
|
74650
|
+
lines.push("", "unstable checks (identical code, different result):");
|
|
74651
|
+
for (const u of report.unstable) {
|
|
74652
|
+
const what = u.flipsStatus ? `status flips ${u.statuses.join(" / ")}` : `issue count varies ${u.issueCounts.join(", ")}`;
|
|
74653
|
+
lines.push(` ${u.flipsStatus ? "FLIP" : "wobble"} ${u.name} — ${what}`);
|
|
74654
|
+
}
|
|
74655
|
+
}
|
|
74656
|
+
if (report.inconsistentlyRun.length > 0) {
|
|
74657
|
+
lines.push("", "ran in some runs and not others (module selection or a precondition, not noise):", ...report.inconsistentlyRun.map((n) => ` ${n}`));
|
|
74658
|
+
}
|
|
74659
|
+
lines.push("", isStable(report, budget) ? "STABLE — a score change on this pair can be attributed to the code" : "UNSTABLE — a score change on this pair cannot yet be attributed to the code");
|
|
74660
|
+
return lines.join(`
|
|
74661
|
+
`);
|
|
74662
|
+
}
|
|
74663
|
+
|
|
74664
|
+
// src/commands/variance.ts
|
|
74665
|
+
function varianceCommand(opts) {
|
|
74666
|
+
if (opts.runIds.length < 2) {
|
|
74667
|
+
console.error(chalk31.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
|
|
74668
|
+
return 2;
|
|
74669
|
+
}
|
|
74670
|
+
const budget = Number.parseFloat(opts.scoreBudget ?? "1");
|
|
74671
|
+
const runs = [];
|
|
74672
|
+
for (const id of opts.runIds) {
|
|
74673
|
+
try {
|
|
74674
|
+
runs.push(loadRun(opts.output, id));
|
|
74675
|
+
} catch (err) {
|
|
74676
|
+
console.error(chalk31.red(` ✖ ${err.message}`));
|
|
74677
|
+
return 2;
|
|
74678
|
+
}
|
|
74679
|
+
}
|
|
74680
|
+
const report = computeVariance(runs);
|
|
74681
|
+
if (opts.json) {
|
|
74682
|
+
console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
|
|
74683
|
+
} else {
|
|
74684
|
+
console.log("");
|
|
74685
|
+
console.log(chalk31.bold(" Score variance"));
|
|
74686
|
+
for (const line of formatVariance(report, { scoreBudget: budget }).split(`
|
|
74687
|
+
`)) {
|
|
74688
|
+
console.log(` ${line}`);
|
|
74689
|
+
}
|
|
74690
|
+
}
|
|
74691
|
+
if (!report.comparable)
|
|
74692
|
+
return 2;
|
|
74693
|
+
return isStable(report, budget) ? 0 : 1;
|
|
74694
|
+
}
|
|
74695
|
+
|
|
72364
74696
|
// src/commands/vitals.ts
|
|
72365
|
-
import { existsSync as
|
|
74697
|
+
import { existsSync as existsSync31, readFileSync as readFileSync36, writeFileSync as writeFileSync31 } from "node:fs";
|
|
72366
74698
|
import { availableParallelism } from "node:os";
|
|
72367
|
-
import { join as
|
|
72368
|
-
import
|
|
74699
|
+
import { join as join41 } from "node:path";
|
|
74700
|
+
import chalk32 from "chalk";
|
|
72369
74701
|
import ora9 from "ora";
|
|
72370
74702
|
|
|
72371
74703
|
// src/checks/agentic-nav.ts
|
|
@@ -72663,10 +74995,10 @@ async function vitalsCommand(opts) {
|
|
|
72663
74995
|
const runId = newRunId();
|
|
72664
74996
|
const paths = createRunDir(opts.output, runId);
|
|
72665
74997
|
const t0 = Date.now();
|
|
72666
|
-
console.log(
|
|
74998
|
+
console.log(chalk32.bold(`
|
|
72667
74999
|
parity vitals ${runId}`));
|
|
72668
|
-
console.log(
|
|
72669
|
-
console.log(
|
|
75000
|
+
console.log(chalk32.dim(` prod: ${opts.prod}`));
|
|
75001
|
+
console.log(chalk32.dim(` cand: ${opts.cand}`));
|
|
72670
75002
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
72671
75003
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
72672
75004
|
if (pagePaths.length === 0) {
|
|
@@ -72698,12 +75030,12 @@ async function vitalsCommand(opts) {
|
|
|
72698
75030
|
completed++;
|
|
72699
75031
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
72700
75032
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
72701
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
75033
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk32.cyan("prod") : chalk32.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
72702
75034
|
}
|
|
72703
75035
|
});
|
|
72704
75036
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
72705
75037
|
if (opts.lighthouse !== false) {
|
|
72706
|
-
const lhDir =
|
|
75038
|
+
const lhDir = join41(paths.runDir, "lighthouse");
|
|
72707
75039
|
const lhCap = opts.lighthouseConcurrency ?? Math.max(1, Math.min(2, Math.floor(availableParallelism() / 2)));
|
|
72708
75040
|
const done = tasks.filter((t) => !!t.capture);
|
|
72709
75041
|
const lhT0 = Date.now();
|
|
@@ -72727,7 +75059,7 @@ async function vitalsCommand(opts) {
|
|
|
72727
75059
|
}
|
|
72728
75060
|
lhCompleted++;
|
|
72729
75061
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
72730
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
75062
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk32.cyan("prod") : chalk32.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
72731
75063
|
});
|
|
72732
75064
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
72733
75065
|
}
|
|
@@ -72792,7 +75124,7 @@ async function vitalsCommand(opts) {
|
|
|
72792
75124
|
writeRunReportJson(paths.runDir, run);
|
|
72793
75125
|
const html = renderHtmlReport(run, paths.runDir);
|
|
72794
75126
|
writeRunReportHtml(paths.runDir, html);
|
|
72795
|
-
writeFileSync31(
|
|
75127
|
+
writeFileSync31(join41(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
72796
75128
|
schemaVersion: "0.1",
|
|
72797
75129
|
prodUrl: opts.prod,
|
|
72798
75130
|
candUrl: opts.cand,
|
|
@@ -72805,8 +75137,8 @@ async function vitalsCommand(opts) {
|
|
|
72805
75137
|
`, "utf8");
|
|
72806
75138
|
printSummary8(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
72807
75139
|
console.log("");
|
|
72808
|
-
console.log(
|
|
72809
|
-
console.log(
|
|
75140
|
+
console.log(chalk32.dim(` → ${paths.reportHtml}`));
|
|
75141
|
+
console.log(chalk32.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
72810
75142
|
console.log("");
|
|
72811
75143
|
if (opts.open) {
|
|
72812
75144
|
const { default: open } = await import("open");
|
|
@@ -72896,15 +75228,15 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
72896
75228
|
function parseUrlList(input) {
|
|
72897
75229
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
72898
75230
|
const path = input.replace(/^file:\/\//, "");
|
|
72899
|
-
if (
|
|
72900
|
-
return
|
|
75231
|
+
if (existsSync31(path)) {
|
|
75232
|
+
return readFileSync36(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
72901
75233
|
}
|
|
72902
75234
|
}
|
|
72903
75235
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
72904
75236
|
}
|
|
72905
75237
|
function printSummary8(vitals, cache, scores, opportunities, agentic) {
|
|
72906
75238
|
console.log("");
|
|
72907
|
-
console.log(
|
|
75239
|
+
console.log(chalk32.bold(" Summary:"));
|
|
72908
75240
|
console.log(` ${vitals.summary}`);
|
|
72909
75241
|
console.log(` ${cache.summary}`);
|
|
72910
75242
|
if (scores.status !== "skipped")
|
|
@@ -72915,27 +75247,6 @@ function printSummary8(vitals, cache, scores, opportunities, agentic) {
|
|
|
72915
75247
|
console.log(` ${agentic.summary}`);
|
|
72916
75248
|
}
|
|
72917
75249
|
|
|
72918
|
-
// src/util/version.ts
|
|
72919
|
-
import { readFileSync as readFileSync34 } from "node:fs";
|
|
72920
|
-
import { dirname as dirname6, resolve as resolve9 } from "node:path";
|
|
72921
|
-
import { fileURLToPath } from "node:url";
|
|
72922
|
-
function getPackageVersion() {
|
|
72923
|
-
try {
|
|
72924
|
-
const here = dirname6(fileURLToPath(import.meta.url));
|
|
72925
|
-
for (const up of ["..", "../..", "../../.."]) {
|
|
72926
|
-
try {
|
|
72927
|
-
const pkgPath = resolve9(here, up, "package.json");
|
|
72928
|
-
const raw = readFileSync34(pkgPath, "utf8");
|
|
72929
|
-
const parsed = JSON.parse(raw);
|
|
72930
|
-
if (parsed.name === "@decocms/parity" && typeof parsed.version === "string") {
|
|
72931
|
-
return parsed.version;
|
|
72932
|
-
}
|
|
72933
|
-
} catch {}
|
|
72934
|
-
}
|
|
72935
|
-
} catch {}
|
|
72936
|
-
return "0.0.0";
|
|
72937
|
-
}
|
|
72938
|
-
|
|
72939
75250
|
// src/cli.ts
|
|
72940
75251
|
var program = new Command;
|
|
72941
75252
|
function deprecatedNotice(oldCmd, newCmd) {
|
|
@@ -72988,8 +75299,14 @@ program.command("list").description("List saved runs").option("--output <dir>",
|
|
|
72988
75299
|
}).addCommand(new Command("modules").description("List the 8 selectable check modules (M3 module selection) with their descriptions, checks, and flows — see --only/--skip on `parity run`.").option("--json", "Emit structured JSON instead of human-readable text", false).action((opts) => {
|
|
72989
75300
|
process.exit(listModulesCommand(Boolean(opts.json)));
|
|
72990
75301
|
}));
|
|
72991
|
-
program.command("plan").description("Inspect/update the migration-plan.json component contract").addCommand(new Command("set-status").description("Mark a component's outcome as the orchestrator works. `as-is` = divergence accepted (prod is still the reference); `upgrade` = the target is deliberately ahead, so prod is NOT the reference — pair it with `plan set-reference`.").argument("<name>", "Component name (case- and separator-insensitive)").argument("<status>", "pending | partial | done | as-is | upgrade | skipped").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, status, opts) => {
|
|
72992
|
-
|
|
75302
|
+
program.command("plan").description("Inspect/update the migration-plan.json component contract").addCommand(new Command("set-status").description("Mark a component's outcome as the orchestrator works. `as-is` = divergence accepted (prod is still the reference); `upgrade` = the target is deliberately ahead, so prod is NOT the reference — pair it with `plan set-reference`.").argument("<name>", "Component name (case- and separator-insensitive)").argument("<status>", "pending | partial | done | as-is | upgrade | skipped").option("--create <scope>", "Create the row when the capture never found this component — `global` or `page`. A zero-height overlay header or a portal-rendered panel can be missed by detection, which leaves the plan unable to hold a decision about it. Recorded as origin `manual`, so it stays visible that somebody added it rather than the capture observing it.").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, status, opts) => {
|
|
75303
|
+
if (opts.create && opts.create !== "global" && opts.create !== "page") {
|
|
75304
|
+
console.error("--create must be `global` or `page`");
|
|
75305
|
+
process.exit(2);
|
|
75306
|
+
}
|
|
75307
|
+
process.exit(planSetStatusCommand(opts.dir, name, status, {
|
|
75308
|
+
create: opts.create
|
|
75309
|
+
}));
|
|
72993
75310
|
})).addCommand(new Command("set-page-status").description("Mark a page pending|code|done|skipped (code = route built, content missing)").argument("<path>", "Page path, e.g. / or /refrigeracion").argument("<status>", "pending | code | done | skipped").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((path, status, opts) => {
|
|
72994
75311
|
process.exit(planSetPageStatusCommand(opts.dir, path, status));
|
|
72995
75312
|
})).addCommand(new Command("status").description("Migration inventory: components settled vs remaining, pages done vs awaiting CMS content").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").option("--json", "Emit structured JSON instead of human-readable text", false).action((opts) => {
|
|
@@ -73010,7 +75327,7 @@ program.command("plan").description("Inspect/update the migration-plan.json comp
|
|
|
73010
75327
|
page: opts.page,
|
|
73011
75328
|
post: opts.post
|
|
73012
75329
|
}));
|
|
73013
|
-
})).addCommand(new Command("set-reference").description("Point a component's comparison at something other than prod (a site the better component came from), and record WHY it diverges. Without this, an intentional improvement is reported as a defect on every run.").argument("<name>", "Component name (case- and separator-insensitive)").requiredOption("--note <why>", "Why this component diverges — required, not decoration").option("--url <url>", "Reference site base URL (default: the plan's prod URL)").option("--selector <sel>", "Selector on the reference site, when it differs").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, opts) => {
|
|
75330
|
+
})).addCommand(new Command("set-provenance").description("Record where a shipped component came from: `library` (reused from the shared target template) or `built` (written for this migration). A multi-store rollout is priced on store N costing less than store N-1, and reuse is the only mechanism that delivers that — unrecorded, 'the next one is cheaper' stays an assertion.").argument("<name>", "Component name (case- and separator-insensitive)").argument("<provenance>", "library | built").option("--dir <dir>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, provenance, o) => process.exit(planSetProvenanceCommand(o.dir, name, provenance)))).addCommand(new Command("touch").description("Count one human intervention against a page — a person pointing at a defect the tooling did not surface. This is the metric that says whether the loop is converging: one real page took fourteen rounds of pasted screenshots. A counter, not a log; the magnitude is the signal.").argument("<page>", "Page path, e.g. /").option("--dir <dir>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").option("--json", "Emit one-line JSON instead of pretty text", false).action((page, o) => process.exit(planTouchCommand(o.dir, page, { json: o.json })))).addCommand(new Command("set-reference").description("Point a component's comparison at something other than prod (a site the better component came from), and record WHY it diverges. Without this, an intentional improvement is reported as a defect on every run.").argument("<name>", "Component name (case- and separator-insensitive)").requiredOption("--note <why>", "Why this component diverges — required, not decoration").option("--url <url>", "Reference site base URL (default: the plan's prod URL)").option("--selector <sel>", "Selector on the reference site, when it differs").option("--dir <path>", "Directory holding migration-plan.json (default: the target repo's .parity/)", ".parity").action((name, opts) => {
|
|
73014
75331
|
process.exit(planSetReferenceCommand(opts.dir, name, {
|
|
73015
75332
|
url: opts.url,
|
|
73016
75333
|
selector: opts.selector,
|
|
@@ -73211,8 +75528,9 @@ program.command("check").argument("<name>", "check name (kebab-case, e.g. consol
|
|
|
73211
75528
|
json: opts.json
|
|
73212
75529
|
}));
|
|
73213
75530
|
});
|
|
73214
|
-
program.command("section").description("Focused prod×cand comparison of one section: HTML diff + screenshot + computed-styles diff, plus an opt-in numeric box-tree diff (--box-tree). No flags = all 3 facets. Designed for the 'in DOM but invisible' debug loop (issue #31).").requiredOption("--prod <url>", "Production URL (base, e.g. https://www.example.com)").requiredOption("--cand <url>", "Candidate URL (base, e.g. https://example.deco-cx.workers.dev)").requiredOption("--selector <sel>", "CSS selector for the section to compare").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side, when the ported component no longer matches --selector (VTEX IO class names → hashed CSS Modules, data-fs-* attributes, …). Defaults to --selector.").option("--output-html", "Include the HTML diff facet (default: on if no facet flag passed)", false).option("--screenshot", "Include the screenshot facet (locator screenshot per side)", false).option("--computed-styles", "Include the computed-styles diff facet", false).option("--heatmap", "Run pixelmatch on the two screenshots and analyze diff regions (bounding box + hotspots). Implies --screenshot.", false).option("--box-tree", "Walk the selector's whole subtree on both sides and report numeric box deltas, biggest first (`margin-top: 32px → 24px -8`). Deterministic, no LLM — this is the answer to 'everything is a little off', which a pixelmatch percentage and a vision paragraph cannot give.", false).option("--css-source", "For each divergent computed-style property, resolve which CSS rule (stylesheet + selector) produced it via CDP. Useful when the LLM needs to know which file to edit.", false).option("--prompt", "Emit an LLM-ready bundle: <prefix>-bundle.json (machine-readable) + <prefix>-prompt.md (opinionated Markdown with embedded images). Implies all signals.", false).option("--llm-summary", "After building the bundle, invoke Claude (needs ANTHROPIC_API_KEY) and print a 1-paragraph 'what I understood' summary. Does NOT generate a patch. Implies --prompt.", false).option("--all", "Turn on every diagnostic facet at once (html + screenshot + computed-styles + heatmap + css-source + prompt + llm-summary) — the pixel-perfect debug shortcut formerly known as `parity fix`. Issue #415.", false).option("--no-llm", "With --all, skip the LLM call (still writes the markdown bundle). Use when offline or to avoid API costs.").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--out-dir <dir>", "Where to write the screenshots", "./parity-output/sections").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
75531
|
+
program.command("section").description("Focused prod×cand comparison of one section: HTML diff + screenshot + computed-styles diff, plus an opt-in numeric box-tree diff (--box-tree). No flags = all 3 facets. Designed for the 'in DOM but invisible' debug loop (issue #31).").requiredOption("--prod <url>", "Production URL (base, e.g. https://www.example.com)").requiredOption("--cand <url>", "Candidate URL (base, e.g. https://example.deco-cx.workers.dev)").requiredOption("--selector <sel>", "CSS selector for the section to compare").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side, when the ported component no longer matches --selector (VTEX IO class names → hashed CSS Modules, data-fs-* attributes, …). Defaults to --selector.").option("--output-html", "Include the HTML diff facet (default: on if no facet flag passed)", false).option("--screenshot", "Include the screenshot facet (locator screenshot per side)", false).option("--computed-styles", "Include the computed-styles diff facet", false).option("--heatmap", "Run pixelmatch on the two screenshots and analyze diff regions (bounding box + hotspots). Implies --screenshot.", false).option("--box-tree", "Walk the selector's whole subtree on both sides and report numeric box deltas, biggest first (`margin-top: 32px → 24px -8`). Deterministic, no LLM — this is the answer to 'everything is a little off', which a pixelmatch percentage and a vision paragraph cannot give.", false).option("--css-source", "For each divergent computed-style property, resolve which CSS rule (stylesheet + selector) produced it via CDP. Useful when the LLM needs to know which file to edit.", false).option("--prompt", "Emit an LLM-ready bundle: <prefix>-bundle.json (machine-readable) + <prefix>-prompt.md (opinionated Markdown with embedded images). Implies all signals.", false).option("--llm-summary", "After building the bundle, invoke Claude (needs ANTHROPIC_API_KEY) and print a 1-paragraph 'what I understood' summary. Does NOT generate a patch. Implies --prompt.", false).option("--all", "Turn on every diagnostic facet at once (html + screenshot + computed-styles + heatmap + css-source + prompt + llm-summary) — the pixel-perfect debug shortcut formerly known as `parity fix`. Issue #415.", false).option("--no-llm", "With --all, skip the LLM call (still writes the markdown bundle). Use when offline or to avoid API costs.").option("--viewport <viewport>", "mobile | desktop | tablet", "mobile").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--out-dir <dir>", "Where to write the screenshots", "./parity-output/sections").option("--plan-dir <dir>", "Run dir holding migration-plan.json. Its component rows are the only place the prod-side spelling of a component (`site/sections/Hero/HeroBannerV2.tsx`) and the cand-side one (`HeroSlideshow`) are written down together, so reading it lets the label pass pair nodes whose markup does not agree. Without it, unlabelled nodes fall back to the structural path.").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
73215
75532
|
process.exit(await sectionCommand({
|
|
75533
|
+
planDir: opts.planDir,
|
|
73216
75534
|
prod: opts.prod,
|
|
73217
75535
|
cand: opts.cand,
|
|
73218
75536
|
selector: opts.selector,
|
|
@@ -73231,7 +75549,47 @@ program.command("section").description("Focused prod×cand comparison of one sec
|
|
|
73231
75549
|
json: opts.json
|
|
73232
75550
|
}));
|
|
73233
75551
|
});
|
|
73234
|
-
program.command("
|
|
75552
|
+
program.command("cockpit").description("Serve the migration on a local page: the per-page board, a page worksheet, the box-tree and motion deltas from `parity bench`, and the latest run's verdict. Reads artifacts already on disk — nothing new is computed, and the lane rules stay in the plan so the page cannot disagree with the CLI. Local, single-user, read-only.").option("--dir <dir>", "Directory holding migration-plan.json + migration.json (default: the target repo's .parity/)", ".parity").option("--output <dir>", "Directory holding runs/", "./parity-output").option("--bench-dir <dir>", "Directory holding bench-*.json", "./parity-output/bench").option("--prod <url>", "Production URL, to show the side-by-side panes").option("--cand <url>", "Candidate URL, to show the side-by-side panes").option("--port <port>", "Port to bind (default: an open one)").option("--host <host>", "Interface to bind. Defaults to loopback: the server is unauthenticated, reads the repo, and proxies arbitrary URLs with frame protections stripped.", "127.0.0.1").option("--no-open", "Do not open a browser").action(async (opts) => {
|
|
75553
|
+
process.exit(await cockpitCommand({
|
|
75554
|
+
dir: opts.dir,
|
|
75555
|
+
output: opts.output,
|
|
75556
|
+
benchDir: opts.benchDir,
|
|
75557
|
+
prodUrl: opts.prod,
|
|
75558
|
+
candUrl: opts.cand,
|
|
75559
|
+
port: opts.port,
|
|
75560
|
+
host: opts.host,
|
|
75561
|
+
open: opts.open
|
|
75562
|
+
}));
|
|
75563
|
+
});
|
|
75564
|
+
program.command("mcp").description("Expose the migration over MCP on stdio: state, plan status, the per-page board, a page worksheet, saved run verdicts, and (with --allow-writes) the status/provenance/touch verbs. Thin wrappers over what the CLI already computes — no second brain. This is a server, not a UI: rendering a board is a job for whatever host consumes MCP, and keeping the lane rules here is what stops a second implementation of them drifting somewhere else.").option("--dir <dir>", "Directory holding migration-plan.json + migration.json (default: the target repo's .parity/)", ".parity").option("--output <dir>", "Directory holding runs/", "./parity-output").option("--cand-url <url>", "Candidate base URL, so worksheets and boards can build runnable commands").option("--allow-writes", "Let the mutating tools run. Off by default: an MCP client can call anything the server lists, and the plan is committed state.", false).action(async (opts) => {
|
|
75565
|
+
process.exit(await mcpCommand({
|
|
75566
|
+
dir: opts.dir,
|
|
75567
|
+
output: opts.output,
|
|
75568
|
+
candUrl: opts.candUrl,
|
|
75569
|
+
allowWrites: opts.allowWrites
|
|
75570
|
+
}));
|
|
75571
|
+
});
|
|
75572
|
+
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) => {
|
|
75573
|
+
process.exit(varianceCommand({
|
|
75574
|
+
runIds,
|
|
75575
|
+
output: opts.output,
|
|
75576
|
+
scoreBudget: opts.scoreBudget,
|
|
75577
|
+
json: opts.json
|
|
75578
|
+
}));
|
|
75579
|
+
});
|
|
75580
|
+
program.command("locate").description("Where is this element on each side? Give it a label — a data-section value or the text the element starts with — and it reports the node it matched on each side, its box and its type, at one or more viewports. It REFUSES when either side has more than one candidate instead of taking the first, which is the mistake every hand-written version of this makes. Exits 1 when any label could not be located on both sides.").requiredOption("--prod <url>", "Reference URL").requiredOption("--cand <url>", "Candidate URL").option("--label <text...>", "A data-section/data-testid value, or the text the element starts with. Repeatable.").option("--selector <sel>", "Root to search inside", "body").option("--viewports <list>", "Comma-separated: mobile, tablet, desktop. A type defect is often one breakpoint, so measuring three is how you tell a responsive rule from a broken one.", "mobile,desktop").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--plan-dir <dir>", "Run dir holding migration-plan.json, so a source-side spelling of a component resolves to the cand-side name.").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
75581
|
+
process.exit(await locateCommand({
|
|
75582
|
+
prod: opts.prod,
|
|
75583
|
+
cand: opts.cand,
|
|
75584
|
+
labels: opts.label ?? [],
|
|
75585
|
+
selector: opts.selector,
|
|
75586
|
+
viewports: opts.viewports,
|
|
75587
|
+
wait: opts.wait,
|
|
75588
|
+
planDir: opts.planDir,
|
|
75589
|
+
json: opts.json
|
|
75590
|
+
}));
|
|
75591
|
+
});
|
|
75592
|
+
program.command("bench").description("Compare ONE component in ISOLATION. Both sides mount it at a harness route (/__parity/bench?component=X&props=<base64>) with the same props, so the page stops being a confounder: no lazy-load timing, no carousel position, no cookie banner, no A/B flag. Seconds per run instead of a full-page capture, so many components can converge concurrently. Pass --prod-selector to compare against a live page instead of a second harness.").requiredOption("--component <name>", "Component name the harness route resolves").requiredOption("--cand <url>", "Candidate harness base URL (e.g. http://localhost:3000)").requiredOption("--prod <url>", "Reference: a second harness base (the source repo's dev server), or a live page when --prod-selector is given").option("--props <file>", "JSON file of props to mount with. Prefer the real values from the source CMS over invented ones — a component fed placeholder content converges on placeholder layout.").option("--selector <sel>", "Component root inside the harness", "[data-parity-bench]").option("--prod-selector <sel>", "Treat --prod as a live PAGE and find the component at this selector. Use before a source dev server exists.").option("--cand-selector <sel>", "Same, for the candidate side").option("--viewport <viewport>", "mobile | desktop | tablet", "desktop").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "1000").option("--out-dir <dir>", "Where to write screenshots + the result JSON", "./parity-output/bench").option("--fail-on-diff", "Exit 1 when geometry or motion is not clean (for a convergence loop)", false).option("--plan-dir <dir>", "Run dir holding migration-plan.json — its component rows carry both sides' spellings of a component, so the label pass can pair nodes whose markup does not agree.").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
73235
75593
|
process.exit(await benchCommand({
|
|
73236
75594
|
component: opts.component,
|
|
73237
75595
|
prod: opts.prod,
|
|
@@ -73244,16 +75602,20 @@ program.command("bench").description("Compare ONE component in ISOLATION. Both s
|
|
|
73244
75602
|
wait: opts.wait,
|
|
73245
75603
|
outDir: opts.outDir,
|
|
73246
75604
|
failOnDiff: opts.failOnDiff,
|
|
75605
|
+
planDir: opts.planDir,
|
|
73247
75606
|
json: opts.json
|
|
73248
75607
|
}));
|
|
73249
75608
|
});
|
|
73250
|
-
program.command("states").description("Compare a component's INTERACTIVE states, not just its resting frame. Two deterministic signals: declared motion (transitions, animations and the @keyframes bodies they point at, per interactive element) and hover effects (hover each element in turn, re-read the box tree, and report which effects prod has that cand lost). This is the instrument behind 'the hover effects are not the same' — no LLM, no screenshots to eyeball.").requiredOption("--prod <url>", "Production URL (source of truth)").requiredOption("--cand <url>", "Candidate URL (migrated)").
|
|
75609
|
+
program.command("states").description("Compare a component's INTERACTIVE states, not just its resting frame. Two deterministic signals: declared motion (transitions, animations and the @keyframes bodies they point at, per interactive element) and hover effects (hover each element in turn, re-read the box tree, and report which effects prod has that cand lost). This is the instrument behind 'the hover effects are not the same' — no LLM, no screenshots to eyeball.").requiredOption("--prod <url>", "Production URL (source of truth)").requiredOption("--cand <url>", "Candidate URL (migrated)").option("--selector <sel>", "CSS selector for the component, on both sides. Shorthand for passing --prod-selector and --cand-selector the same value.").option("--prod-selector <sel>", "CSS selector on the PRODUCTION side. On a legacy-to-modern migration the two sides frequently share no selector at all — a prod PDP with no <main>, a header nine levels deeper than the port's — and widening to `body` to find one string that resolves on both is the worst place to run this. Give each side its own.").option("--cand-selector <sel>", "CSS selector on the CANDIDATE side. Defaults to --selector.").option("--max-states <n>", "How many interactive elements to hover per side. A mega-nav has hundreds of links sharing one hover rule; N distinct effects is the signal.", "12").option("--hover-settle <ms>", "Wait after hovering before re-reading. A pure CSS transition needs none — its end state is already in the computed style on the first frame — but anything gated on a JS timer (hover intent, a debounce) needs the whole timer, and 'moves nothing' measured too early reads exactly like a broken hover. When the first read finds nothing, a second is taken at 4x this before concluding, so a site without hover-intent never pays for one.", "250").option("--viewport <viewport>", "mobile | desktop | tablet", "desktop").option("--wait <ms>", "Extra ms after networkidle so hydration settles", "2000").option("--plan-dir <dir>", "Run dir holding migration-plan.json. Its component rows are the only place the prod-side spelling of a component (`site/sections/Hero/HeroBannerV2.tsx`) and the cand-side one (`HeroSlideshow`) are written down together, so reading it lets the label pass pair nodes whose markup does not agree. Without it, unlabelled nodes fall back to the structural path.").option("--json", "Emit one-line JSON instead of pretty text", false).action(async (opts) => {
|
|
73251
75610
|
process.exit(await statesCommand({
|
|
75611
|
+
planDir: opts.planDir,
|
|
73252
75612
|
prod: opts.prod,
|
|
73253
75613
|
cand: opts.cand,
|
|
73254
75614
|
selector: opts.selector,
|
|
75615
|
+
prodSelector: opts.prodSelector,
|
|
73255
75616
|
candSelector: opts.candSelector,
|
|
73256
75617
|
maxStates: opts.maxStates,
|
|
75618
|
+
hoverSettle: opts.hoverSettle,
|
|
73257
75619
|
viewport: opts.viewport,
|
|
73258
75620
|
wait: opts.wait,
|
|
73259
75621
|
json: opts.json
|