@decocms/parity 0.35.24 → 0.35.25
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/CHANGELOG.md +6 -0
- package/dist/cli.js +449 -108
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -32,6 +32,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
32
32
|
(`sitemap` | `links` | `explicit`, profile + evidence, templates with example
|
|
33
33
|
URLs, what the cap left out). All plan additions are optional, so existing plans
|
|
34
34
|
still load and `parity plan merge` carries them.
|
|
35
|
+
* **`parity replay <dir>`** re-runs the checks on a `--record` recording with no browser and scores
|
|
36
|
+
them with the same code as `parity run`. `--expect` / `--update-expected` pin the outcome (check
|
|
37
|
+
statuses, issue ids, verdict status) in `<dir>/expected.json`; exit 2 means nothing could be
|
|
38
|
+
judged (never a pass). A request the recording never saw fails the check and is named. A corpus
|
|
39
|
+
suite (`tests/corpus/corpus.test.ts`, `PARITY_CORPUS_DIR`) replays a directory of reviewed
|
|
40
|
+
recordings kept in a separate private repository. See `docs/reports.md`.
|
|
35
41
|
|
|
36
42
|
### Fixed
|
|
37
43
|
|
package/dist/cli.js
CHANGED
|
@@ -75779,7 +75779,7 @@ import {
|
|
|
75779
75779
|
registerCommands as registerCatalogCommands
|
|
75780
75780
|
} from "@decocms/catalog";
|
|
75781
75781
|
import { DESCRIPTION, registerCommands } from "@decocms/vtex-cms";
|
|
75782
|
-
import
|
|
75782
|
+
import chalk49 from "chalk";
|
|
75783
75783
|
import { Command, InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
75784
75784
|
|
|
75785
75785
|
// src/commands/ab-detect.ts
|
|
@@ -117649,6 +117649,65 @@ function saveCheckContext(dir, ctx, meta) {
|
|
|
117649
117649
|
RecordedContext.parse(recorded);
|
|
117650
117650
|
writeFileSync32(join44(dir, CONTEXT_FILE), JSON.stringify(recorded), "utf8");
|
|
117651
117651
|
}
|
|
117652
|
+
function loadCheckContext(dir) {
|
|
117653
|
+
const file = join44(dir, CONTEXT_FILE);
|
|
117654
|
+
if (!existsSync29(file))
|
|
117655
|
+
throw new Error(`${dir} holds no recording (${CONTEXT_FILE} not found)`);
|
|
117656
|
+
const raw = JSON.parse(readFileSync38(file, "utf8"));
|
|
117657
|
+
if (raw.formatVersion !== FORMAT_VERSION) {
|
|
117658
|
+
throw new Error(`${file}: unsupported recording formatVersion ${JSON.stringify(raw.formatVersion)} (this parity reads ${FORMAT_VERSION})`);
|
|
117659
|
+
}
|
|
117660
|
+
const r = RecordedContext.parse(raw);
|
|
117661
|
+
const root = resolve20(dir);
|
|
117662
|
+
const abs = (p) => p === "" || isAbsolute(p) ? p : join44(root, p);
|
|
117663
|
+
const absOpt = (p) => p ? abs(p) : p;
|
|
117664
|
+
const page = (c) => ({ ...c, screenshotPath: abs(c.screenshotPath) });
|
|
117665
|
+
const step = (s) => ({
|
|
117666
|
+
...s,
|
|
117667
|
+
screenshotPath: abs(s.screenshotPath),
|
|
117668
|
+
...s.screenshotBeforePath !== undefined ? { screenshotBeforePath: abs(s.screenshotBeforePath) } : {}
|
|
117669
|
+
});
|
|
117670
|
+
const flow = (f) => ({
|
|
117671
|
+
...f,
|
|
117672
|
+
pages: f.pages.map(page),
|
|
117673
|
+
...f.steps ? { steps: f.steps.map(step) } : {}
|
|
117674
|
+
});
|
|
117675
|
+
const fetchFile = join44(dir, FETCH_FILE);
|
|
117676
|
+
if (!existsSync29(fetchFile)) {
|
|
117677
|
+
throw new Error(`${dir} is an incomplete recording: ${FETCH_FILE} is missing (the run stopped during checks?)`);
|
|
117678
|
+
}
|
|
117679
|
+
const fetchLog = FetchLogSchema.parse(JSON.parse(readFileSync38(fetchFile, "utf8")));
|
|
117680
|
+
return {
|
|
117681
|
+
ctx: {
|
|
117682
|
+
prodPages: r.prodPages.map(page),
|
|
117683
|
+
candPages: r.candPages.map(page),
|
|
117684
|
+
prodFlows: r.prodFlows.map(flow),
|
|
117685
|
+
candFlows: r.candFlows.map(flow),
|
|
117686
|
+
rc: r.rc,
|
|
117687
|
+
ignore: r.ignore,
|
|
117688
|
+
viewports: r.viewports,
|
|
117689
|
+
...r.candIsProduction !== undefined ? { candIsProduction: r.candIsProduction } : {},
|
|
117690
|
+
visualProbes: r.visualProbes ? new Map(r.visualProbes.map(([k, v]) => [
|
|
117691
|
+
abs(k),
|
|
117692
|
+
{
|
|
117693
|
+
...v,
|
|
117694
|
+
side: { ...v.side, screenshot: absOpt(v.side.screenshot) },
|
|
117695
|
+
repeatScreenshot: absOpt(v.repeatScreenshot)
|
|
117696
|
+
}
|
|
117697
|
+
])) : undefined
|
|
117698
|
+
},
|
|
117699
|
+
meta: {
|
|
117700
|
+
prodUrl: r.prodUrl,
|
|
117701
|
+
candUrl: r.candUrl,
|
|
117702
|
+
recordedAt: r.recordedAt,
|
|
117703
|
+
...r.checkNames ? { checkNames: r.checkNames } : {},
|
|
117704
|
+
...r.parityVersion ? { parityVersion: r.parityVersion } : {}
|
|
117705
|
+
},
|
|
117706
|
+
fetchLog,
|
|
117707
|
+
missingFiles: r.missingFiles,
|
|
117708
|
+
omittedArtifacts: r.omittedArtifacts
|
|
117709
|
+
};
|
|
117710
|
+
}
|
|
117652
117711
|
var FetchEntry = z4.object({
|
|
117653
117712
|
method: z4.string(),
|
|
117654
117713
|
url: z4.string(),
|
|
@@ -117728,6 +117787,61 @@ function saveFetchLog(dir, log) {
|
|
|
117728
117787
|
writeFileSync32(join44(dir, FETCH_FILE), JSON.stringify(log), "utf8");
|
|
117729
117788
|
}
|
|
117730
117789
|
|
|
117790
|
+
class UnrecordedFetchError extends Error {
|
|
117791
|
+
name = "UnrecordedFetchError";
|
|
117792
|
+
constructor(method, url) {
|
|
117793
|
+
super(`replay: ${method} ${url} was not made during the recorded run`);
|
|
117794
|
+
}
|
|
117795
|
+
}
|
|
117796
|
+
function createReplayFetch(log) {
|
|
117797
|
+
const queues = new Map;
|
|
117798
|
+
for (const e of log.entries) {
|
|
117799
|
+
const k = `${e.method} ${e.url}`;
|
|
117800
|
+
const q = queues.get(k);
|
|
117801
|
+
if (q)
|
|
117802
|
+
q.push(e);
|
|
117803
|
+
else
|
|
117804
|
+
queues.set(k, [e]);
|
|
117805
|
+
}
|
|
117806
|
+
const cursor = new Map;
|
|
117807
|
+
return async (input, init) => {
|
|
117808
|
+
const { method, url } = reqParts(input, init);
|
|
117809
|
+
const k = `${method} ${url}`;
|
|
117810
|
+
const q = queues.get(k);
|
|
117811
|
+
if (!q)
|
|
117812
|
+
throw new UnrecordedFetchError(method, url);
|
|
117813
|
+
const i = cursor.get(k) ?? 0;
|
|
117814
|
+
cursor.set(k, Math.min(i + 1, q.length - 1));
|
|
117815
|
+
const e = q[i];
|
|
117816
|
+
if (e.error) {
|
|
117817
|
+
const err = e.error.name === "TypeError" ? new TypeError(e.error.message) : new Error(e.error.message);
|
|
117818
|
+
err.name = e.error.name;
|
|
117819
|
+
if (e.error.cause)
|
|
117820
|
+
err.cause = { code: e.error.cause };
|
|
117821
|
+
throw err;
|
|
117822
|
+
}
|
|
117823
|
+
const status = e.status ?? 200;
|
|
117824
|
+
let body = null;
|
|
117825
|
+
if (e.bodyError) {
|
|
117826
|
+
const msg = e.bodyError;
|
|
117827
|
+
body = new ReadableStream({ start: (c) => c.error(new Error(msg)) });
|
|
117828
|
+
} else if (e.body && !NULL_BODY.has(status)) {
|
|
117829
|
+
body = "text" in e.body ? e.body.text : Buffer.from(e.body.base64, "base64");
|
|
117830
|
+
}
|
|
117831
|
+
const res = new Response(body, { status, statusText: e.statusText, headers: e.headers });
|
|
117832
|
+
Object.defineProperty(res, "url", { value: e.finalUrl ?? url });
|
|
117833
|
+
Object.defineProperty(res, "redirected", { value: e.redirected ?? false });
|
|
117834
|
+
return res;
|
|
117835
|
+
};
|
|
117836
|
+
}
|
|
117837
|
+
function replayFetch(log) {
|
|
117838
|
+
const orig = globalThis.fetch;
|
|
117839
|
+
globalThis.fetch = createReplayFetch(log);
|
|
117840
|
+
return () => {
|
|
117841
|
+
globalThis.fetch = orig;
|
|
117842
|
+
};
|
|
117843
|
+
}
|
|
117844
|
+
|
|
117731
117845
|
// src/diff/score-band.ts
|
|
117732
117846
|
var uniq = (xs) => [...new Set(xs)];
|
|
117733
117847
|
function computeScoreBand(current, priors, opts = {}) {
|
|
@@ -117822,6 +117936,34 @@ function readLine2(prompt) {
|
|
|
117822
117936
|
});
|
|
117823
117937
|
}
|
|
117824
117938
|
|
|
117939
|
+
// src/engine/score-run.ts
|
|
117940
|
+
function scoreChecks(checks, ignore, pages) {
|
|
117941
|
+
const allIssues = checks.flatMap((c) => c.issues);
|
|
117942
|
+
const acceptance = applyAcceptedFindings(checks, ignore.expectedDivergences ?? []);
|
|
117943
|
+
const remainingChecks = withoutAccepted(checks);
|
|
117944
|
+
const remainingIssues = remainingChecks.flatMap((c) => c.issues);
|
|
117945
|
+
const pagesAnalyzed = pairCaptures(pages.prodPages, pages.candPages).pairs.length;
|
|
117946
|
+
const scoreOf = (c, i) => {
|
|
117947
|
+
const mv = computeModuleVerdicts(c, i);
|
|
117948
|
+
return {
|
|
117949
|
+
moduleVerdicts: mv,
|
|
117950
|
+
verdict: mv.length > 0 ? computeCompositeVerdict(mv, c, i) : computeVerdict(c, i, { pagesAnalyzed })
|
|
117951
|
+
};
|
|
117952
|
+
};
|
|
117953
|
+
const scored = scoreOf(remainingChecks, remainingIssues);
|
|
117954
|
+
if (acceptance.accepted > 0)
|
|
117955
|
+
scored.verdict.rawScore = scoreOf(checks, allIssues).verdict.score;
|
|
117956
|
+
return {
|
|
117957
|
+
allIssues,
|
|
117958
|
+
acceptance,
|
|
117959
|
+
remainingChecks,
|
|
117960
|
+
remainingIssues,
|
|
117961
|
+
pagesAnalyzed,
|
|
117962
|
+
moduleVerdicts: scored.moduleVerdicts,
|
|
117963
|
+
verdict: scored.verdict
|
|
117964
|
+
};
|
|
117965
|
+
}
|
|
117966
|
+
|
|
117825
117967
|
// src/commands/run.ts
|
|
117826
117968
|
init_client();
|
|
117827
117969
|
|
|
@@ -119153,26 +119295,17 @@ ${formatTimingsSummary(partialTimings, buildFlowBreakdown(allFlowCaptures))}
|
|
|
119153
119295
|
for (const c of checks)
|
|
119154
119296
|
jsonl.write(checkToJsonl(runId, c));
|
|
119155
119297
|
}
|
|
119156
|
-
const
|
|
119157
|
-
|
|
119158
|
-
|
|
119159
|
-
|
|
119298
|
+
const {
|
|
119299
|
+
allIssues,
|
|
119300
|
+
acceptance,
|
|
119301
|
+
remainingIssues,
|
|
119302
|
+
moduleVerdicts,
|
|
119303
|
+
verdict: scored
|
|
119304
|
+
} = scoreChecks(checks, ignore, checkCtx);
|
|
119160
119305
|
const topIssues = rankTopIssues(remainingIssues);
|
|
119161
119306
|
currentPhase = "report";
|
|
119162
|
-
const pagesAnalyzed = pairCaptures(checkCtx.prodPages, checkCtx.candPages).pairs.length;
|
|
119163
|
-
const scoreOf = (c, i) => {
|
|
119164
|
-
const mv = computeModuleVerdicts(c, i);
|
|
119165
|
-
return {
|
|
119166
|
-
moduleVerdicts: mv,
|
|
119167
|
-
verdict: mv.length > 0 ? computeCompositeVerdict(mv, c, i) : computeVerdict(c, i, { pagesAnalyzed })
|
|
119168
|
-
};
|
|
119169
|
-
};
|
|
119170
|
-
const scored = scoreOf(remainingChecks, remainingIssues);
|
|
119171
|
-
const { moduleVerdicts } = scored;
|
|
119172
|
-
if (acceptance.accepted > 0)
|
|
119173
|
-
scored.verdict.rawScore = scoreOf(checks, allIssues).verdict.score;
|
|
119174
119307
|
const pagePairs = explicitPaths ? measurePagePairs(explicitPaths, viewports, { prod: opts.prod, cand: opts.cand }, allPageCaptures) : undefined;
|
|
119175
|
-
const verdict = verdictForPagePairs(scored
|
|
119308
|
+
const verdict = verdictForPagePairs(scored, pagePairs);
|
|
119176
119309
|
if (moduleDropReason) {
|
|
119177
119310
|
verdict.modulesSkipped = [{ module: "e2e", reason: moduleDropReason }];
|
|
119178
119311
|
}
|
|
@@ -122532,24 +122665,229 @@ async function rerenderCommand(opts) {
|
|
|
122532
122665
|
}
|
|
122533
122666
|
}
|
|
122534
122667
|
|
|
122535
|
-
// src/commands/
|
|
122536
|
-
import { existsSync as existsSync38 } from "node:fs";
|
|
122668
|
+
// src/commands/replay.ts
|
|
122537
122669
|
import chalk41 from "chalk";
|
|
122670
|
+
|
|
122671
|
+
// src/replay/outcome.ts
|
|
122672
|
+
import { existsSync as existsSync38, readFileSync as readFileSync45, writeFileSync as writeFileSync38 } from "node:fs";
|
|
122673
|
+
import { join as join52 } from "node:path";
|
|
122674
|
+
import { z as z6 } from "zod";
|
|
122675
|
+
var EXPECTED_FILE = "expected.json";
|
|
122676
|
+
var ReplayOutcome = z6.object({
|
|
122677
|
+
formatVersion: z6.literal(1),
|
|
122678
|
+
parityVersion: z6.string(),
|
|
122679
|
+
generatedAt: z6.string(),
|
|
122680
|
+
checks: z6.record(z6.string(), z6.string()),
|
|
122681
|
+
issues: z6.array(z6.string()),
|
|
122682
|
+
verdict: z6.object({ status: z6.string(), score: z6.number() }),
|
|
122683
|
+
notes: z6.string().optional()
|
|
122684
|
+
});
|
|
122685
|
+
function buildOutcome(checks, issues, verdict, parityVersion) {
|
|
122686
|
+
const byName = Object.fromEntries([...checks].sort((a, b) => a.name.localeCompare(b.name)).map((c) => [c.name, c.status]));
|
|
122687
|
+
return {
|
|
122688
|
+
formatVersion: 1,
|
|
122689
|
+
parityVersion,
|
|
122690
|
+
generatedAt: new Date().toISOString(),
|
|
122691
|
+
checks: byName,
|
|
122692
|
+
issues: [...new Set(issues.map((i) => i.id))].sort(),
|
|
122693
|
+
verdict: { status: verdict.status, score: verdict.score }
|
|
122694
|
+
};
|
|
122695
|
+
}
|
|
122696
|
+
function readExpected(dir) {
|
|
122697
|
+
const file = join52(dir, EXPECTED_FILE);
|
|
122698
|
+
if (!existsSync38(file))
|
|
122699
|
+
throw new Error(`${file} not found (record the expectation with --update-expected)`);
|
|
122700
|
+
return ReplayOutcome.parse(JSON.parse(readFileSync45(file, "utf8")));
|
|
122701
|
+
}
|
|
122702
|
+
function writeExpected(dir, outcome) {
|
|
122703
|
+
const file = join52(dir, EXPECTED_FILE);
|
|
122704
|
+
const notes = existsSync38(file) ? readExpected(dir).notes : undefined;
|
|
122705
|
+
const { notes: _drop, ...rest } = outcome;
|
|
122706
|
+
writeFileSync38(file, `${JSON.stringify({ ...rest, ...notes !== undefined ? { notes } : {} }, null, 2)}
|
|
122707
|
+
`, "utf8");
|
|
122708
|
+
}
|
|
122709
|
+
function diffOutcome(expected, actual) {
|
|
122710
|
+
const names = [
|
|
122711
|
+
...new Set([...Object.keys(expected.checks), ...Object.keys(actual.checks)])
|
|
122712
|
+
].sort();
|
|
122713
|
+
const statusChanged = names.filter((n) => expected.checks[n] !== actual.checks[n]).map((check) => ({
|
|
122714
|
+
check,
|
|
122715
|
+
expected: expected.checks[check] ?? "(absent)",
|
|
122716
|
+
actual: actual.checks[check] ?? "(absent)"
|
|
122717
|
+
}));
|
|
122718
|
+
const exp = new Set(expected.issues);
|
|
122719
|
+
const act = new Set(actual.issues);
|
|
122720
|
+
return {
|
|
122721
|
+
statusChanged,
|
|
122722
|
+
issuesAdded: [...act].filter((i) => !exp.has(i)).sort(),
|
|
122723
|
+
issuesRemoved: [...exp].filter((i) => !act.has(i)).sort(),
|
|
122724
|
+
...expected.verdict.status !== actual.verdict.status ? { verdictChanged: { expected: expected.verdict.status, actual: actual.verdict.status } } : {},
|
|
122725
|
+
...expected.verdict.score !== actual.verdict.score ? { scoreChanged: { expected: expected.verdict.score, actual: actual.verdict.score } } : {}
|
|
122726
|
+
};
|
|
122727
|
+
}
|
|
122728
|
+
function outcomeMatches(d) {
|
|
122729
|
+
return d.statusChanged.length === 0 && d.issuesAdded.length === 0 && d.issuesRemoved.length === 0 && !d.verdictChanged;
|
|
122730
|
+
}
|
|
122731
|
+
function formatDiff(d) {
|
|
122732
|
+
return [
|
|
122733
|
+
...d.statusChanged.map((s) => `check ${s.check}: ${s.expected} -> ${s.actual}`),
|
|
122734
|
+
...d.issuesAdded.map((i) => `issue added: ${i}`),
|
|
122735
|
+
...d.issuesRemoved.map((i) => `issue removed: ${i}`),
|
|
122736
|
+
...d.verdictChanged ? [`verdict: ${d.verdictChanged.expected} -> ${d.verdictChanged.actual}`] : [],
|
|
122737
|
+
...d.scoreChanged ? [`score (informational): ${d.scoreChanged.expected} -> ${d.scoreChanged.actual}`] : []
|
|
122738
|
+
];
|
|
122739
|
+
}
|
|
122740
|
+
|
|
122741
|
+
// src/replay/replay.ts
|
|
122742
|
+
import { mkdirSync as mkdirSync24, mkdtempSync as mkdtempSync2, rmSync as rmSync6 } from "node:fs";
|
|
122743
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
122744
|
+
import { join as join53 } from "node:path";
|
|
122745
|
+
class NothingToJudgeError extends Error {
|
|
122746
|
+
name = "NothingToJudgeError";
|
|
122747
|
+
}
|
|
122748
|
+
async function replayRecording(dir, opts = {}) {
|
|
122749
|
+
const rec = loadCheckContext(dir);
|
|
122750
|
+
const pagePairs = pairCaptures(rec.ctx.prodPages, rec.ctx.candPages).pairs.length;
|
|
122751
|
+
const flows = rec.ctx.prodFlows.length + rec.ctx.candFlows.length;
|
|
122752
|
+
if (pagePairs === 0 && flows === 0) {
|
|
122753
|
+
throw new NothingToJudgeError(`nothing was compared: ${dir} holds no page pairs and no flows`);
|
|
122754
|
+
}
|
|
122755
|
+
const ownsOutDir = opts.outDir === undefined;
|
|
122756
|
+
const outDir = opts.outDir ?? mkdtempSync2(join53(tmpdir3(), "parity-replay-"));
|
|
122757
|
+
mkdirSync24(outDir, { recursive: true });
|
|
122758
|
+
const ctx = { ...rec.ctx, outDir };
|
|
122759
|
+
const unrecorded = new Set;
|
|
122760
|
+
const restore = replayFetch(rec.fetchLog);
|
|
122761
|
+
const replayed = globalThis.fetch;
|
|
122762
|
+
globalThis.fetch = async (input, init) => {
|
|
122763
|
+
try {
|
|
122764
|
+
return await replayed(input, init);
|
|
122765
|
+
} catch (err) {
|
|
122766
|
+
if (err instanceof UnrecordedFetchError)
|
|
122767
|
+
unrecorded.add(err.message.replace(/^replay: /, ""));
|
|
122768
|
+
throw err;
|
|
122769
|
+
}
|
|
122770
|
+
};
|
|
122771
|
+
let checks;
|
|
122772
|
+
try {
|
|
122773
|
+
checks = await runAllChecks(ctx, undefined, rec.meta.checkNames ? new Set(rec.meta.checkNames) : undefined);
|
|
122774
|
+
} finally {
|
|
122775
|
+
restore();
|
|
122776
|
+
if (ownsOutDir)
|
|
122777
|
+
rmSync6(outDir, { recursive: true, force: true });
|
|
122778
|
+
}
|
|
122779
|
+
if (checks.length === 0) {
|
|
122780
|
+
throw new NothingToJudgeError(`nothing was compared: no check ran (recorded selection: ${rec.meta.checkNames?.join(", ") ?? "all"})`);
|
|
122781
|
+
}
|
|
122782
|
+
if (unrecorded.size === 0 && checks.every((c) => c.status === "skipped")) {
|
|
122783
|
+
throw new NothingToJudgeError(`nothing was compared: every check was skipped (${checks.length} checks)`);
|
|
122784
|
+
}
|
|
122785
|
+
const scored = scoreChecks(checks, ctx.ignore, ctx);
|
|
122786
|
+
return {
|
|
122787
|
+
checks,
|
|
122788
|
+
issues: scored.allIssues,
|
|
122789
|
+
verdict: scored.verdict,
|
|
122790
|
+
meta: rec.meta,
|
|
122791
|
+
missingFiles: rec.missingFiles,
|
|
122792
|
+
unrecordedFetches: [...unrecorded].sort(),
|
|
122793
|
+
incomplete: unrecorded.size > 0,
|
|
122794
|
+
pagePairs,
|
|
122795
|
+
outcome: buildOutcome(checks, scored.allIssues, scored.verdict, getPackageVersion())
|
|
122796
|
+
};
|
|
122797
|
+
}
|
|
122798
|
+
|
|
122799
|
+
// src/commands/replay.ts
|
|
122800
|
+
async function replayCommand(dir, opts) {
|
|
122801
|
+
const say = (s) => opts.json ? console.error(s) : console.log(s);
|
|
122802
|
+
if (opts.expect && opts.updateExpected) {
|
|
122803
|
+
console.error("replay: --expect and --update-expected are mutually exclusive");
|
|
122804
|
+
return 2;
|
|
122805
|
+
}
|
|
122806
|
+
let r;
|
|
122807
|
+
try {
|
|
122808
|
+
if (opts.expect)
|
|
122809
|
+
readExpected(dir);
|
|
122810
|
+
r = await replayRecording(dir, { outDir: opts.out });
|
|
122811
|
+
} catch (err) {
|
|
122812
|
+
console.error(chalk41.red(`replay: ${err.message}`));
|
|
122813
|
+
return 2;
|
|
122814
|
+
}
|
|
122815
|
+
if (r.incomplete) {
|
|
122816
|
+
if (opts.json) {
|
|
122817
|
+
console.log(JSON.stringify({ incomplete: true, unrecordedFetches: r.unrecordedFetches, meta: r.meta }, null, 2));
|
|
122818
|
+
}
|
|
122819
|
+
console.error(chalk41.red("replay: INCOMPLETE - the recording predates a request the checks now make; re-record it. Requests not in the recording:"));
|
|
122820
|
+
for (const u of r.unrecordedFetches)
|
|
122821
|
+
console.error(chalk41.red(` ${u}`));
|
|
122822
|
+
return 2;
|
|
122823
|
+
}
|
|
122824
|
+
let diffLines;
|
|
122825
|
+
let code = 0;
|
|
122826
|
+
if (opts.updateExpected) {
|
|
122827
|
+
try {
|
|
122828
|
+
writeExpected(dir, r.outcome);
|
|
122829
|
+
} catch (err) {
|
|
122830
|
+
console.error(chalk41.red(`replay: ${err.message}`));
|
|
122831
|
+
return 2;
|
|
122832
|
+
}
|
|
122833
|
+
} else if (opts.expect) {
|
|
122834
|
+
const d = diffOutcome(readExpected(dir), r.outcome);
|
|
122835
|
+
diffLines = formatDiff(d);
|
|
122836
|
+
if (!outcomeMatches(d))
|
|
122837
|
+
code = 1;
|
|
122838
|
+
}
|
|
122839
|
+
if (opts.json) {
|
|
122840
|
+
console.log(JSON.stringify({
|
|
122841
|
+
meta: r.meta,
|
|
122842
|
+
outcome: r.outcome,
|
|
122843
|
+
verdict: r.verdict,
|
|
122844
|
+
pagePairs: r.pagePairs,
|
|
122845
|
+
missingFiles: r.missingFiles,
|
|
122846
|
+
...diffLines ? { matches: code === 0, diff: diffLines } : {}
|
|
122847
|
+
}, null, 2));
|
|
122848
|
+
return code;
|
|
122849
|
+
}
|
|
122850
|
+
const v = r.verdict;
|
|
122851
|
+
const mark = v.status === "inconclusive" ? chalk41.dim("○") : v.status === "pass" ? chalk41.green("✔") : v.status === "warn" ? chalk41.yellow("⚠") : chalk41.red("✖");
|
|
122852
|
+
const score = v.status === "inconclusive" ? "—" : v.score;
|
|
122853
|
+
say(` ${mark} parity ${v.status.toUpperCase()} · score ${score}/100 · ${r.pagePairs} page pairs`);
|
|
122854
|
+
say(` checks: ${v.checksPassed} pass · ${v.checksFailed} fail · ${v.checksSkipped} skipped`);
|
|
122855
|
+
say(` issues: ${v.critical} critical · ${v.high} high · ${v.medium} medium · ${v.low} low`);
|
|
122856
|
+
say(chalk41.dim(` recorded ${r.meta.recordedAt} with parity ${r.meta.parityVersion ?? "(unknown version)"}`));
|
|
122857
|
+
if (r.missingFiles.length > 0) {
|
|
122858
|
+
say(chalk41.yellow(` ${r.missingFiles.length} referenced file(s) were missing when this was recorded; checks that read them judged less than a full run`));
|
|
122859
|
+
}
|
|
122860
|
+
if (opts.updateExpected)
|
|
122861
|
+
say(chalk41.dim(" expected.json written"));
|
|
122862
|
+
if (diffLines) {
|
|
122863
|
+
if (code === 0)
|
|
122864
|
+
say(chalk41.green(" matches expected.json"));
|
|
122865
|
+
else
|
|
122866
|
+
say(chalk41.red(" differs from expected.json:"));
|
|
122867
|
+
for (const l of diffLines)
|
|
122868
|
+
say(` ${l}`);
|
|
122869
|
+
}
|
|
122870
|
+
return code;
|
|
122871
|
+
}
|
|
122872
|
+
|
|
122873
|
+
// src/commands/serve.ts
|
|
122874
|
+
import { existsSync as existsSync39 } from "node:fs";
|
|
122875
|
+
import chalk42 from "chalk";
|
|
122538
122876
|
async function serveRunAndBlock(runDir, opts = {}) {
|
|
122539
122877
|
let handle;
|
|
122540
122878
|
try {
|
|
122541
122879
|
handle = await startProxyServer(runDir, { port: opts.port });
|
|
122542
122880
|
} catch (err) {
|
|
122543
|
-
console.error(
|
|
122881
|
+
console.error(chalk42.red(` ✖ Falha ao iniciar servidor: ${err.message}`));
|
|
122544
122882
|
return 2;
|
|
122545
122883
|
}
|
|
122546
122884
|
const label = opts.label ?? "parity serve";
|
|
122547
122885
|
console.log("");
|
|
122548
|
-
console.log(
|
|
122549
|
-
console.log(` ${
|
|
122550
|
-
console.log(
|
|
122551
|
-
console.log(
|
|
122552
|
-
console.log(
|
|
122886
|
+
console.log(chalk42.bold(` ${label}`));
|
|
122887
|
+
console.log(` ${chalk42.green("●")} ${handle.url}`);
|
|
122888
|
+
console.log(chalk42.dim(` Servindo: ${runDir}`));
|
|
122889
|
+
console.log(chalk42.dim(` Proxy de iframes: ${handle.url}proxy?url=<encoded>`));
|
|
122890
|
+
console.log(chalk42.dim(` Ctrl+C pra parar (2x pra forçar saída).
|
|
122553
122891
|
`));
|
|
122554
122892
|
if (opts.open !== false) {
|
|
122555
122893
|
const { default: open } = await import("open");
|
|
@@ -122581,14 +122919,14 @@ async function serveRunAndBlock(runDir, opts = {}) {
|
|
|
122581
122919
|
}
|
|
122582
122920
|
async function serveCommand(runId, opts) {
|
|
122583
122921
|
const paths = getRunPaths(opts.output, runId);
|
|
122584
|
-
if (!
|
|
122585
|
-
console.error(
|
|
122922
|
+
if (!existsSync39(paths.runDir)) {
|
|
122923
|
+
console.error(chalk42.red(`✖ Run não encontrado: ${runId} (em ${opts.output})`));
|
|
122586
122924
|
return 1;
|
|
122587
122925
|
}
|
|
122588
122926
|
try {
|
|
122589
122927
|
ensureReportHtml(paths);
|
|
122590
122928
|
} catch (err) {
|
|
122591
|
-
console.error(
|
|
122929
|
+
console.error(chalk42.red(`✖ não foi possível gerar report.html: ${err.message}`));
|
|
122592
122930
|
return 1;
|
|
122593
122931
|
}
|
|
122594
122932
|
return serveRunAndBlock(paths.runDir, {
|
|
@@ -122599,7 +122937,7 @@ async function serveCommand(runId, opts) {
|
|
|
122599
122937
|
}
|
|
122600
122938
|
|
|
122601
122939
|
// src/commands/states.ts
|
|
122602
|
-
import
|
|
122940
|
+
import chalk43 from "chalk";
|
|
122603
122941
|
var ROOT_ATTR = "data-parity-states";
|
|
122604
122942
|
var rootSelector = (i) => `[${ROOT_ATTR}="${i}"]`;
|
|
122605
122943
|
function resolveStateRoots(args) {
|
|
@@ -122908,7 +123246,7 @@ function statesVerdict(counts) {
|
|
|
122908
123246
|
async function statesCommand(opts) {
|
|
122909
123247
|
const viewport = parseViewport(opts.viewport);
|
|
122910
123248
|
if (!viewport) {
|
|
122911
|
-
console.error(
|
|
123249
|
+
console.error(chalk43.red(`--viewport inválido: ${opts.viewport}`));
|
|
122912
123250
|
return 2;
|
|
122913
123251
|
}
|
|
122914
123252
|
const waitMs = Number.parseInt(opts.wait, 10) || 0;
|
|
@@ -122918,12 +123256,12 @@ async function statesCommand(opts) {
|
|
|
122918
123256
|
const prodSelector = opts.prodSelector?.trim() || opts.selector?.trim();
|
|
122919
123257
|
const candSelector = opts.candSelector?.trim() || opts.selector?.trim();
|
|
122920
123258
|
if (!prodSelector || !candSelector) {
|
|
122921
|
-
console.error(
|
|
123259
|
+
console.error(chalk43.red(" informe --selector (ambos os lados) ou --prod-selector e --cand-selector"));
|
|
122922
123260
|
return 2;
|
|
122923
123261
|
}
|
|
122924
123262
|
const { aliases, note: aliasNote } = resolveAliases(opts.planDir);
|
|
122925
123263
|
if (aliasNote)
|
|
122926
|
-
console.log(
|
|
123264
|
+
console.log(chalk43.dim(` ${aliasNote}`));
|
|
122927
123265
|
const browser = await launchBrowser({ headless: true });
|
|
122928
123266
|
try {
|
|
122929
123267
|
const [prodSide, candSide] = await Promise.all([
|
|
@@ -122948,7 +123286,7 @@ async function statesCommand(opts) {
|
|
|
122948
123286
|
]);
|
|
122949
123287
|
if (prodSide.baseError || candSide.baseError) {
|
|
122950
123288
|
const which = prodSide.baseError ? `prod: ${prodSide.baseError}` : `cand: ${candSide.baseError}`;
|
|
122951
|
-
console.error(
|
|
123289
|
+
console.error(chalk43.red(` não foi possível ler o componente — ${which}`));
|
|
122952
123290
|
return 2;
|
|
122953
123291
|
}
|
|
122954
123292
|
for (const [name, side, sel] of [
|
|
@@ -122957,13 +123295,13 @@ async function statesCommand(opts) {
|
|
|
122957
123295
|
]) {
|
|
122958
123296
|
const r = side.resolution;
|
|
122959
123297
|
if (r?.kind === "ambiguous") {
|
|
122960
|
-
console.error(
|
|
123298
|
+
console.error(chalk43.red(` ${name}: ${sel} matches ${r.total} visible elements and none looks like a product card (image + link + price). Narrow it to one:`));
|
|
122961
123299
|
for (const sample of r.samples)
|
|
122962
|
-
console.error(
|
|
123300
|
+
console.error(chalk43.dim(` ${sample}`));
|
|
122963
123301
|
return 2;
|
|
122964
123302
|
}
|
|
122965
123303
|
if (!r || r.kind === "none") {
|
|
122966
|
-
console.error(
|
|
123304
|
+
console.error(chalk43.red(` ${name}: ${sel} matches no visible element${r?.error ? ` — ${r.error}` : ""}`));
|
|
122967
123305
|
return 2;
|
|
122968
123306
|
}
|
|
122969
123307
|
}
|
|
@@ -123045,21 +123383,21 @@ async function statesCommand(opts) {
|
|
|
123045
123383
|
]) {
|
|
123046
123384
|
const caveat = data.settle && formatSettleCaveat(name, data.settle);
|
|
123047
123385
|
if (caveat)
|
|
123048
|
-
console.log(
|
|
123386
|
+
console.log(chalk43.yellow(` ${caveat}`));
|
|
123049
123387
|
}
|
|
123050
123388
|
if (cardMode) {
|
|
123051
123389
|
console.log("");
|
|
123052
|
-
console.log(
|
|
123390
|
+
console.log(chalk43.bold(` Product cards: ${pairing.pairs.length} pair(s) — ${pairing.pairs.map(([p, c]) => `prod #${p + 1} ↔ cand #${c + 1}`).join(", ") || "none"}`));
|
|
123053
123391
|
for (const [name, side] of [
|
|
123054
123392
|
["prod", prodSide],
|
|
123055
123393
|
["cand", candSide]
|
|
123056
123394
|
]) {
|
|
123057
123395
|
const r = side.resolution;
|
|
123058
123396
|
if (r?.kind === "cards" && r.ignored > 0) {
|
|
123059
|
-
console.log(
|
|
123397
|
+
console.log(chalk43.dim(` ${name}: ${r.ignored} matched element(s) are not product cards and were ignored`));
|
|
123060
123398
|
}
|
|
123061
123399
|
if (r?.kind === "single" && !r.isCard) {
|
|
123062
|
-
console.log(
|
|
123400
|
+
console.log(chalk43.yellow(` ${name}: the selector names one element that is not a product card; it is never paired with a card`));
|
|
123063
123401
|
}
|
|
123064
123402
|
}
|
|
123065
123403
|
const unpaired = [
|
|
@@ -123067,65 +123405,65 @@ async function statesCommand(opts) {
|
|
|
123067
123405
|
...pairing.unpairedCand.map((i) => `cand #${i + 1}`)
|
|
123068
123406
|
];
|
|
123069
123407
|
if (unpaired.length)
|
|
123070
|
-
console.log(
|
|
123408
|
+
console.log(chalk43.dim(` UNPAIRED cards: ${unpaired.join(", ")} — not compared`));
|
|
123071
123409
|
if (pairing.pairs.length === 0) {
|
|
123072
|
-
console.log(
|
|
123410
|
+
console.log(chalk43.yellow(" INCONCLUSIVE — no card paired, so nothing was compared."));
|
|
123073
123411
|
}
|
|
123074
123412
|
}
|
|
123075
123413
|
console.log("");
|
|
123076
|
-
console.log(
|
|
123414
|
+
console.log(chalk43.bold(" Declared motion"));
|
|
123077
123415
|
if (!motion) {
|
|
123078
123416
|
const err = prodFlat.motionError ?? candFlat.motionError ?? "nothing paired";
|
|
123079
|
-
console.log(
|
|
123417
|
+
console.log(chalk43.yellow(` não foi possível comparar — ${err}`));
|
|
123080
123418
|
} else {
|
|
123081
123419
|
for (const line of formatMotionDiff(motion).split(`
|
|
123082
123420
|
`))
|
|
123083
123421
|
console.log(` ${line}`);
|
|
123084
123422
|
}
|
|
123085
123423
|
console.log("");
|
|
123086
|
-
console.log(
|
|
123424
|
+
console.log(chalk43.bold(` Hover effects (${prodFlat.effects.length} prod / ${candFlat.effects.length} cand)`));
|
|
123087
123425
|
const nothing = effects.lost.length === 0 && effects.changed.length === 0 && effects.added.length === 0 && effects.unpaired.length === 0;
|
|
123088
123426
|
if (nothing && !exercised) {
|
|
123089
|
-
console.log(
|
|
123427
|
+
console.log(chalk43.yellow(" INCONCLUSIVE — no hover changed anything on either side, so nothing was exercised. Check the selector holds an interactive element."));
|
|
123090
123428
|
} else if (nothing) {
|
|
123091
123429
|
console.log(" clean — every hover that changes something in prod changes the same in cand");
|
|
123092
123430
|
}
|
|
123093
123431
|
for (const e of effects.lost) {
|
|
123094
|
-
console.log(
|
|
123432
|
+
console.log(chalk43.red(` LOST ${e.target}${e.label ? ` (${e.label})` : ""} — prod moves [${e.properties.join(", ")}]; cand's element was hovered and moved nothing`));
|
|
123095
123433
|
}
|
|
123096
123434
|
for (const { prod, extra, notComparable, onElement } of effects.changed) {
|
|
123097
123435
|
console.log(` DIFFERS ${prod.target}${prod.label ? ` (${prod.label})` : ""}`);
|
|
123098
123436
|
if (onElement.length) {
|
|
123099
|
-
console.log(
|
|
123437
|
+
console.log(chalk43.yellow(` prod also moves [${onElement.join(", ")}] on the element itself`));
|
|
123100
123438
|
}
|
|
123101
123439
|
if (extra.length)
|
|
123102
123440
|
console.log(` cand also moves [${extra.join(", ")}]`);
|
|
123103
123441
|
if (notComparable.length) {
|
|
123104
|
-
console.log(
|
|
123442
|
+
console.log(chalk43.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.`));
|
|
123105
123443
|
}
|
|
123106
123444
|
if (onElement.length === 0 && extra.length === 0) {
|
|
123107
|
-
console.log(
|
|
123445
|
+
console.log(chalk43.dim(" nothing comparable differs."));
|
|
123108
123446
|
}
|
|
123109
123447
|
}
|
|
123110
123448
|
for (const e of effects.unpaired) {
|
|
123111
|
-
console.log(
|
|
123449
|
+
console.log(chalk43.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)`));
|
|
123112
123450
|
}
|
|
123113
123451
|
for (const e of effects.added) {
|
|
123114
123452
|
console.log(` ADDED ${e.target} — cand moves [${e.properties.join(", ")}]; prod does not`);
|
|
123115
123453
|
}
|
|
123116
123454
|
if (effects.unpaired.length > 0 && effects.lost.length === 0 && effects.changed.length === 0) {
|
|
123117
123455
|
console.log("");
|
|
123118
|
-
console.log(
|
|
123456
|
+
console.log(chalk43.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.`));
|
|
123119
123457
|
}
|
|
123120
123458
|
const prodAmbient = prodSide.roots.reduce((n, r) => n + r.ambient, 0);
|
|
123121
123459
|
const candAmbient = candSide.roots.reduce((n, r) => n + r.ambient, 0);
|
|
123122
123460
|
if (prodAmbient > 0 || candAmbient > 0) {
|
|
123123
|
-
console.log(
|
|
123461
|
+
console.log(chalk43.dim(` ${prodAmbient} prod / ${candAmbient} 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.`));
|
|
123124
123462
|
}
|
|
123125
123463
|
for (const cap of caps)
|
|
123126
|
-
console.log(
|
|
123464
|
+
console.log(chalk43.yellow(` CAPPED — ${cap}; absence of a finding is not proof`));
|
|
123127
123465
|
if (truncated) {
|
|
123128
|
-
console.log(
|
|
123466
|
+
console.log(chalk43.dim(" TRUNCATED — box-tree or motion node cap hit; absence of a finding is not proof"));
|
|
123129
123467
|
}
|
|
123130
123468
|
return inconclusive || effects.lost.length > 0 || (motion?.findings.length ?? 0) > 0 ? 1 : 0;
|
|
123131
123469
|
} finally {
|
|
@@ -123137,7 +123475,7 @@ async function statesCommand(opts) {
|
|
|
123137
123475
|
|
|
123138
123476
|
// src/commands/stress.ts
|
|
123139
123477
|
import { createHash as createHash3 } from "node:crypto";
|
|
123140
|
-
import
|
|
123478
|
+
import chalk44 from "chalk";
|
|
123141
123479
|
var STATIC = /\.(png|jpe?g|webp|avif|gif|svg|woff2?|ttf|css|js|map|ico)(\?|$)/i;
|
|
123142
123480
|
function analyzeStress(requests, extra) {
|
|
123143
123481
|
const groups = new Map;
|
|
@@ -123167,7 +123505,7 @@ function analyzeStress(requests, extra) {
|
|
|
123167
123505
|
}
|
|
123168
123506
|
async function stressCommand(opts) {
|
|
123169
123507
|
if (!opts.selector && !opts.text) {
|
|
123170
|
-
console.error(
|
|
123508
|
+
console.error(chalk44.red("pass --selector or --text"));
|
|
123171
123509
|
return 2;
|
|
123172
123510
|
}
|
|
123173
123511
|
const browser = await launchBrowser({ headless: true });
|
|
@@ -123194,7 +123532,7 @@ async function stressCommand(opts) {
|
|
|
123194
123532
|
const target = (opts.selector ? page.locator(opts.selector) : page.getByText(opts.text, { exact: true })).filter({ visible: true }).first();
|
|
123195
123533
|
const box = await target.boundingBox().catch(() => null);
|
|
123196
123534
|
if (!box) {
|
|
123197
|
-
console.error(
|
|
123535
|
+
console.error(chalk44.yellow("target matched no visible element — nothing was stressed"));
|
|
123198
123536
|
return 2;
|
|
123199
123537
|
}
|
|
123200
123538
|
const handle = await target.elementHandle().catch(() => null);
|
|
@@ -123245,17 +123583,17 @@ async function stressCommand(opts) {
|
|
|
123245
123583
|
console.log(JSON.stringify({ url: opts.url, target: opts.selector ?? opts.text, ...report }));
|
|
123246
123584
|
return 0;
|
|
123247
123585
|
}
|
|
123248
|
-
console.log(
|
|
123586
|
+
console.log(chalk44.bold(`
|
|
123249
123587
|
${opts.times} clicks on ${opts.selector ?? `"${opts.text}"`}`));
|
|
123250
123588
|
console.log(` ${report.requests} request(s), ${report.mutations} mutating · disabled after 1st click: ${report.disabledAfterFirstClick ?? "?"}`);
|
|
123251
123589
|
for (const d of report.duplicates)
|
|
123252
|
-
console.log(
|
|
123590
|
+
console.log(chalk44.yellow(` ×${d.count} ${d.method} ${d.url.slice(0, 110)} [${d.statuses.join(",")}]`));
|
|
123253
123591
|
for (const f of report.failed.filter((f) => !report.duplicates.includes(f)))
|
|
123254
|
-
console.log(
|
|
123592
|
+
console.log(chalk44.red(` failed ${f.method} ${f.url.slice(0, 110)} [${f.statuses.join(",")}]`));
|
|
123255
123593
|
for (const e of report.consoleErrors.slice(0, 5))
|
|
123256
|
-
console.log(
|
|
123594
|
+
console.log(chalk44.red(` console: ${e}`));
|
|
123257
123595
|
if (opts.screenshot)
|
|
123258
|
-
console.log(
|
|
123596
|
+
console.log(chalk44.dim(` final state: ${opts.screenshot}`));
|
|
123259
123597
|
return 0;
|
|
123260
123598
|
} finally {
|
|
123261
123599
|
await browser.close().catch(() => {
|
|
@@ -123266,18 +123604,18 @@ async function stressCommand(opts) {
|
|
|
123266
123604
|
|
|
123267
123605
|
// src/commands/studio.ts
|
|
123268
123606
|
import { execFileSync as execFileSync6 } from "node:child_process";
|
|
123269
|
-
import
|
|
123607
|
+
import chalk45 from "chalk";
|
|
123270
123608
|
var CLOSED2 = new Set(["done", "archived", "merged"]);
|
|
123271
123609
|
var PRIORITY_RANK = { urgent: 0, high: 1, medium: 2, low: 3, none: 4 };
|
|
123272
123610
|
function config() {
|
|
123273
123611
|
const cfg = studioConfigFromEnv();
|
|
123274
123612
|
if (!cfg) {
|
|
123275
|
-
console.error(
|
|
123613
|
+
console.error(chalk45.red(`Studio not configured — ${STUDIO_LOGIN_HINT}. The org comes from PARITY_STUDIO_URL (…/api/<org>/mcp/self) or PARITY_STUDIO_ORG.`));
|
|
123276
123614
|
}
|
|
123277
123615
|
return cfg;
|
|
123278
123616
|
}
|
|
123279
123617
|
function fail2(err) {
|
|
123280
|
-
console.error(
|
|
123618
|
+
console.error(chalk45.red(err instanceof Error ? err.message : String(err)));
|
|
123281
123619
|
return 1;
|
|
123282
123620
|
}
|
|
123283
123621
|
function seq(t) {
|
|
@@ -123285,7 +123623,7 @@ function seq(t) {
|
|
|
123285
123623
|
}
|
|
123286
123624
|
function line(t) {
|
|
123287
123625
|
const tags = [t.type, t.priority && t.priority !== "none" ? t.priority : null].filter(Boolean).join("·");
|
|
123288
|
-
return `${
|
|
123626
|
+
return `${chalk45.bold(seq(t).padEnd(6))} ${t.status.padEnd(12)} ${chalk45.dim(`[${tags}]`.padEnd(16))} ${t.title}${t.repo ? chalk45.dim(` ${t.repo}`) : ""}`;
|
|
123289
123627
|
}
|
|
123290
123628
|
async function resolveTask(cfg, ref, call) {
|
|
123291
123629
|
const board = await listTasks2(cfg, call);
|
|
@@ -123309,13 +123647,13 @@ async function studioTasksCommand(opts, call = callTool2) {
|
|
|
123309
123647
|
return 0;
|
|
123310
123648
|
}
|
|
123311
123649
|
if (board.items.length === 0) {
|
|
123312
|
-
console.log(
|
|
123650
|
+
console.log(chalk45.yellow("The board is empty."));
|
|
123313
123651
|
return 0;
|
|
123314
123652
|
}
|
|
123315
123653
|
for (const t of limited)
|
|
123316
123654
|
console.log(line(t));
|
|
123317
123655
|
const hidden = board.items.length - shown.length;
|
|
123318
|
-
console.log(
|
|
123656
|
+
console.log(chalk45.dim(` ${shown.length} of ${board.items.length} task(s)${limited.length < shown.length ? `, first ${limited.length} shown` : ""}${hidden > 0 && !statuses && !opts.all ? ` · ${hidden} done/archived/merged or filtered out (--all shows them)` : ""}`));
|
|
123319
123657
|
return 0;
|
|
123320
123658
|
} catch (err) {
|
|
123321
123659
|
return fail2(err);
|
|
@@ -123339,23 +123677,23 @@ async function studioShowCommand(opts, call = callTool2) {
|
|
|
123339
123677
|
return 0;
|
|
123340
123678
|
}
|
|
123341
123679
|
console.log(line(task));
|
|
123342
|
-
console.log(
|
|
123680
|
+
console.log(chalk45.dim(` id ${task.id}${task.statusSince ? ` · in ${task.status} since ${task.statusSince}` : ""}`));
|
|
123343
123681
|
if (task.description)
|
|
123344
123682
|
console.log(`
|
|
123345
123683
|
${task.description}
|
|
123346
123684
|
`);
|
|
123347
123685
|
if (prs === null)
|
|
123348
|
-
console.log(
|
|
123686
|
+
console.log(chalk45.dim(" (could not read linked PRs)"));
|
|
123349
123687
|
for (const pr of prs ?? []) {
|
|
123350
123688
|
const state = pr.merged ? "merged" : pr.draft ? "draft" : pr.state ?? "?";
|
|
123351
|
-
console.log(` PR ${state.padEnd(7)} ${pr.url}${pr.title ?
|
|
123689
|
+
console.log(` PR ${state.padEnd(7)} ${pr.url}${pr.title ? chalk45.dim(` ${pr.title}`) : ""}`);
|
|
123352
123690
|
}
|
|
123353
123691
|
const open = comments.filter((c) => !c.resolved);
|
|
123354
123692
|
if (open.length)
|
|
123355
|
-
console.log(
|
|
123693
|
+
console.log(chalk45.bold(`
|
|
123356
123694
|
Comments (${open.length} open)`));
|
|
123357
123695
|
for (const c of open)
|
|
123358
|
-
console.log(` ${
|
|
123696
|
+
console.log(` ${chalk45.dim(c.createdAt)} ${c.body.replace(/\n/g, `
|
|
123359
123697
|
`)}`);
|
|
123360
123698
|
return 0;
|
|
123361
123699
|
} catch (err) {
|
|
@@ -123374,7 +123712,7 @@ async function guardedMove(cfg, task, columns, to, opts, call) {
|
|
|
123374
123712
|
if (!valid.includes(to))
|
|
123375
123713
|
return fail2(new Error(`"${to}" is not a column of this board: ${valid.join(", ")}.`));
|
|
123376
123714
|
if (task.status === to) {
|
|
123377
|
-
console.log(
|
|
123715
|
+
console.log(chalk45.dim(`${seq(task)} is already in ${to}.`));
|
|
123378
123716
|
return 0;
|
|
123379
123717
|
}
|
|
123380
123718
|
const automated = await automatedColumns(cfg, call);
|
|
@@ -123382,16 +123720,16 @@ async function guardedMove(cfg, task, columns, to, opts, call) {
|
|
|
123382
123720
|
return fail2(new Error(`The "${to}" column has an automation: landing ${seq(task)} there starts the board's agent on it. Pass --allow-automation if that is the point.`));
|
|
123383
123721
|
}
|
|
123384
123722
|
if (!opts.yes) {
|
|
123385
|
-
console.log(
|
|
123723
|
+
console.log(chalk45.yellow("dry run — nothing changed. Pass --yes."));
|
|
123386
123724
|
console.log(` ${seq(task)} ${task.status} → ${to} ${task.title}`);
|
|
123387
123725
|
if (opts.comment)
|
|
123388
|
-
console.log(
|
|
123726
|
+
console.log(chalk45.dim(` and comment: ${PARITY_COMMENT_PREFIX} ${opts.comment}`));
|
|
123389
123727
|
return 0;
|
|
123390
123728
|
}
|
|
123391
123729
|
await moveTask(cfg, task.id, to, call);
|
|
123392
123730
|
if (opts.comment)
|
|
123393
123731
|
await postParityComment(task.id, opts.comment, cfg, call);
|
|
123394
|
-
console.log(`${
|
|
123732
|
+
console.log(`${chalk45.green("✓")} ${seq(task)} ${task.status} → ${to} ${task.title}`);
|
|
123395
123733
|
return 0;
|
|
123396
123734
|
}
|
|
123397
123735
|
async function studioTakeCommand(opts, call = callTool2) {
|
|
@@ -123440,12 +123778,12 @@ async function studioCommentCommand(opts, call = callTool2) {
|
|
|
123440
123778
|
if (found instanceof Error)
|
|
123441
123779
|
return fail2(found);
|
|
123442
123780
|
if (!opts.yes) {
|
|
123443
|
-
console.log(
|
|
123781
|
+
console.log(chalk45.yellow("dry run — nothing posted. Pass --yes."));
|
|
123444
123782
|
console.log(` on ${seq(found.task)}: ${PARITY_COMMENT_PREFIX} ${body}`);
|
|
123445
123783
|
return 0;
|
|
123446
123784
|
}
|
|
123447
123785
|
await postParityComment(found.task.id, body, cfg, call);
|
|
123448
|
-
console.log(`${
|
|
123786
|
+
console.log(`${chalk45.green("✓")} commented on ${seq(found.task)}`);
|
|
123449
123787
|
return 0;
|
|
123450
123788
|
} catch (err) {
|
|
123451
123789
|
return fail2(err);
|
|
@@ -123454,9 +123792,9 @@ async function studioCommentCommand(opts, call = callTool2) {
|
|
|
123454
123792
|
|
|
123455
123793
|
// src/commands/drift.ts
|
|
123456
123794
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
123457
|
-
import { existsSync as
|
|
123795
|
+
import { existsSync as existsSync40, readFileSync as readFileSync46 } from "node:fs";
|
|
123458
123796
|
import { resolve as resolve23 } from "node:path";
|
|
123459
|
-
import
|
|
123797
|
+
import chalk46 from "chalk";
|
|
123460
123798
|
var DRIFT_EXCLUDES = [":!.deco"];
|
|
123461
123799
|
var SHA_RE = /^[0-9a-f]{7,64}$/i;
|
|
123462
123800
|
function resolveDriftInputs(state, flags) {
|
|
@@ -123574,7 +123912,7 @@ function computeDrift(inputs, opts) {
|
|
|
123574
123912
|
const fail = (code, message) => ({ error: { code, message } });
|
|
123575
123913
|
if (headRef.startsWith("-"))
|
|
123576
123914
|
return fail("bad_head", `head "${headRef}" looks like a flag`);
|
|
123577
|
-
if (!
|
|
123915
|
+
if (!existsSync40(source))
|
|
123578
123916
|
return fail("not_a_repo", `${source} does not exist`);
|
|
123579
123917
|
const inside = git(source, ["rev-parse", "--is-inside-work-tree"]);
|
|
123580
123918
|
if (!inside.ok || inside.stdout.trim() !== "true") {
|
|
@@ -123642,10 +123980,10 @@ function computeDrift(inputs, opts) {
|
|
|
123642
123980
|
};
|
|
123643
123981
|
}
|
|
123644
123982
|
function loadState(path) {
|
|
123645
|
-
if (!
|
|
123983
|
+
if (!existsSync40(path))
|
|
123646
123984
|
return null;
|
|
123647
123985
|
try {
|
|
123648
|
-
return JSON.parse(
|
|
123986
|
+
return JSON.parse(readFileSync46(path, "utf8"));
|
|
123649
123987
|
} catch (err) {
|
|
123650
123988
|
return { error: { code: "state_unreadable", message: `${path}: ${err.message}` } };
|
|
123651
123989
|
}
|
|
@@ -123669,7 +124007,7 @@ function driftCommand(flags) {
|
|
|
123669
124007
|
if (flags.json)
|
|
123670
124008
|
console.log(JSON.stringify({ error: r.error }));
|
|
123671
124009
|
else
|
|
123672
|
-
console.error(
|
|
124010
|
+
console.error(chalk46.red(` could not measure drift [${r.error.code}]: ${r.error.message}`));
|
|
123673
124011
|
return 2;
|
|
123674
124012
|
}
|
|
123675
124013
|
if (flags.json) {
|
|
@@ -123688,7 +124026,7 @@ function driftCommand(flags) {
|
|
|
123688
124026
|
}
|
|
123689
124027
|
|
|
123690
124028
|
// src/commands/variance.ts
|
|
123691
|
-
import
|
|
124029
|
+
import chalk47 from "chalk";
|
|
123692
124030
|
|
|
123693
124031
|
// src/diff/variance.ts
|
|
123694
124032
|
var uniq2 = (xs) => [...new Set(xs)];
|
|
@@ -123792,7 +124130,7 @@ function formatVariance(report, opts = {}) {
|
|
|
123792
124130
|
// src/commands/variance.ts
|
|
123793
124131
|
function varianceCommand(opts) {
|
|
123794
124132
|
if (opts.runIds.length < 2) {
|
|
123795
|
-
console.error(
|
|
124133
|
+
console.error(chalk47.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
|
|
123796
124134
|
return 2;
|
|
123797
124135
|
}
|
|
123798
124136
|
const budget = Number.parseFloat(opts.scoreBudget ?? "1");
|
|
@@ -123801,7 +124139,7 @@ function varianceCommand(opts) {
|
|
|
123801
124139
|
try {
|
|
123802
124140
|
runs.push(loadRun(opts.output, id));
|
|
123803
124141
|
} catch (err) {
|
|
123804
|
-
console.error(
|
|
124142
|
+
console.error(chalk47.red(` ✖ ${err.message}`));
|
|
123805
124143
|
return 2;
|
|
123806
124144
|
}
|
|
123807
124145
|
}
|
|
@@ -123810,7 +124148,7 @@ function varianceCommand(opts) {
|
|
|
123810
124148
|
console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
|
|
123811
124149
|
} else {
|
|
123812
124150
|
console.log("");
|
|
123813
|
-
console.log(
|
|
124151
|
+
console.log(chalk47.bold(" Score variance"));
|
|
123814
124152
|
for (const line of formatVariance(report, { scoreBudget: budget }).split(`
|
|
123815
124153
|
`)) {
|
|
123816
124154
|
console.log(` ${line}`);
|
|
@@ -123822,10 +124160,10 @@ function varianceCommand(opts) {
|
|
|
123822
124160
|
}
|
|
123823
124161
|
|
|
123824
124162
|
// src/commands/vitals.ts
|
|
123825
|
-
import { existsSync as
|
|
124163
|
+
import { existsSync as existsSync41, readFileSync as readFileSync47, writeFileSync as writeFileSync39 } from "node:fs";
|
|
123826
124164
|
import { availableParallelism } from "node:os";
|
|
123827
|
-
import { join as
|
|
123828
|
-
import
|
|
124165
|
+
import { join as join54 } from "node:path";
|
|
124166
|
+
import chalk48 from "chalk";
|
|
123829
124167
|
import ora9 from "ora";
|
|
123830
124168
|
|
|
123831
124169
|
// src/checks/agentic-nav.ts
|
|
@@ -124129,10 +124467,10 @@ async function vitalsCommand(opts) {
|
|
|
124129
124467
|
const runId = newRunId();
|
|
124130
124468
|
const paths = createRunDir(opts.output, runId);
|
|
124131
124469
|
const t0 = Date.now();
|
|
124132
|
-
console.log(
|
|
124470
|
+
console.log(chalk48.bold(`
|
|
124133
124471
|
parity vitals ${runId}`));
|
|
124134
|
-
console.log(
|
|
124135
|
-
console.log(
|
|
124472
|
+
console.log(chalk48.dim(` prod: ${opts.prod}`));
|
|
124473
|
+
console.log(chalk48.dim(` cand: ${opts.cand}`));
|
|
124136
124474
|
const discoverSpinner = ora9("Descobrindo páginas…").start();
|
|
124137
124475
|
const pagePaths = await discoverPagePaths2(opts.prod, opts);
|
|
124138
124476
|
if (pagePaths.length === 0) {
|
|
@@ -124164,12 +124502,12 @@ async function vitalsCommand(opts) {
|
|
|
124164
124502
|
completed++;
|
|
124165
124503
|
const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
|
|
124166
124504
|
const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
|
|
124167
|
-
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ?
|
|
124505
|
+
progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk48.cyan("prod") : chalk48.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
124168
124506
|
}
|
|
124169
124507
|
});
|
|
124170
124508
|
progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
|
|
124171
124509
|
if (opts.lighthouse !== false) {
|
|
124172
|
-
const lhDir =
|
|
124510
|
+
const lhDir = join54(paths.runDir, "lighthouse");
|
|
124173
124511
|
const lhCap = opts.lighthouseConcurrency ?? Math.max(1, Math.min(2, Math.floor(availableParallelism() / 2)));
|
|
124174
124512
|
const done = tasks.filter((t) => !!t.capture);
|
|
124175
124513
|
const lhT0 = Date.now();
|
|
@@ -124193,7 +124531,7 @@ async function vitalsCommand(opts) {
|
|
|
124193
124531
|
}
|
|
124194
124532
|
lhCompleted++;
|
|
124195
124533
|
const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
|
|
124196
|
-
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ?
|
|
124534
|
+
lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk48.cyan("prod") : chalk48.magenta("cand")} ${task.path} (${task.viewport})`;
|
|
124197
124535
|
});
|
|
124198
124536
|
lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
|
|
124199
124537
|
}
|
|
@@ -124258,7 +124596,7 @@ async function vitalsCommand(opts) {
|
|
|
124258
124596
|
writeRunReportJson(paths.runDir, run);
|
|
124259
124597
|
const html = renderHtmlReport(run, paths.runDir);
|
|
124260
124598
|
writeRunReportHtml(paths.runDir, html);
|
|
124261
|
-
|
|
124599
|
+
writeFileSync39(join54(paths.runDir, "vitals.json"), `${JSON.stringify({
|
|
124262
124600
|
schemaVersion: "0.1",
|
|
124263
124601
|
prodUrl: opts.prod,
|
|
124264
124602
|
candUrl: opts.cand,
|
|
@@ -124271,8 +124609,8 @@ async function vitalsCommand(opts) {
|
|
|
124271
124609
|
`, "utf8");
|
|
124272
124610
|
printSummary9(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
|
|
124273
124611
|
console.log("");
|
|
124274
|
-
console.log(
|
|
124275
|
-
console.log(
|
|
124612
|
+
console.log(chalk48.dim(` → ${paths.reportHtml}`));
|
|
124613
|
+
console.log(chalk48.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
|
|
124276
124614
|
console.log("");
|
|
124277
124615
|
if (opts.open) {
|
|
124278
124616
|
const { default: open } = await import("open");
|
|
@@ -124364,15 +124702,15 @@ async function discoverPagePaths2(prodUrl, opts) {
|
|
|
124364
124702
|
function parseUrlList(input) {
|
|
124365
124703
|
if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
|
|
124366
124704
|
const path = input.replace(/^file:\/\//, "");
|
|
124367
|
-
if (
|
|
124368
|
-
return
|
|
124705
|
+
if (existsSync41(path)) {
|
|
124706
|
+
return readFileSync47(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
|
|
124369
124707
|
}
|
|
124370
124708
|
}
|
|
124371
124709
|
return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
|
|
124372
124710
|
}
|
|
124373
124711
|
function printSummary9(vitals, cache, scores, opportunities, agentic) {
|
|
124374
124712
|
console.log("");
|
|
124375
|
-
console.log(
|
|
124713
|
+
console.log(chalk48.bold(" Summary:"));
|
|
124376
124714
|
console.log(` ${vitals.summary}`);
|
|
124377
124715
|
console.log(` ${cache.summary}`);
|
|
124378
124716
|
if (scores.status !== "skipped")
|
|
@@ -124436,10 +124774,10 @@ sweep.addCommand(new Command("regress").description("Run only the store's tests/
|
|
|
124436
124774
|
if (opts.json)
|
|
124437
124775
|
console.log(JSON.stringify({ url: opts.url, issues }));
|
|
124438
124776
|
else if (!issues.length)
|
|
124439
|
-
console.log(
|
|
124777
|
+
console.log(chalk49.green(" regression suite: all passed"));
|
|
124440
124778
|
else
|
|
124441
124779
|
for (const i of issues)
|
|
124442
|
-
console.log((i.inconclusive ?
|
|
124780
|
+
console.log((i.inconclusive ? chalk49.yellow : chalk49.red)(` ${i.summary}`));
|
|
124443
124781
|
process.exit(regressed ? 1 : unverified ? 2 : 0);
|
|
124444
124782
|
}));
|
|
124445
124783
|
sweep.addCommand(new Command("file").description("File an existing sweep run's findings on the Studio board (default: the newest sweep run). Merges <run>/sweeper-issues.json written by the `sweeper` agent. Dry run unless --yes.").option("--run <runId>", "Sweep run id (default: newest sweep in --output)").option("--output <dir>", "Output directory", "./parity-output").option("--board <name>", "Board: studio", "studio").option("--yes", "Actually create/update cards", false).option("--allow-automation", "File even if the board's triage column starts an agent", false).option("--min-severity <sev>", "critical|high|medium|low", "medium").option("--repo <owner/name>", "Repository to put on the cards").option("--artifacts-url <url>", "Public base URL for this run's artifacts").option("--json", "Emit JSON", false).action(async (opts) => {
|
|
@@ -124455,6 +124793,9 @@ program.command("baseline").description("Manage baselines").addCommand(new Comma
|
|
|
124455
124793
|
})).addCommand(new Command("unset").argument("<name>", "Baseline name to remove").action((name) => {
|
|
124456
124794
|
process.exit(baselineUnset(name));
|
|
124457
124795
|
})).addCommand(buildCompareCommand("diff", false));
|
|
124796
|
+
program.command("replay").description("Re-run the checks on a recording made with `parity run --record <dir>`, with no browser. Exit 0 = replayed (and matched expected.json with --expect), 1 = differs from expected.json, 2 = nothing could be judged (not a recording, incomplete, nothing compared, no expected.json).").argument("<dir>", "Recording directory").option("--json", "Emit structured JSON", false).option("--out <dir>", "Keep artifacts (diff PNGs) here instead of a temp dir removed afterwards").option("--expect", "Compare the outcome with <dir>/expected.json", false).option("--update-expected", "Write <dir>/expected.json from this replay (keeps its notes)", false).action(async (dir, opts) => {
|
|
124797
|
+
process.exit(await replayCommand(dir, opts));
|
|
124798
|
+
});
|
|
124458
124799
|
program.command("accept").description("Record findings the USER accepted as-is, in .parityignore. They stay in the report but leave the headline score (`rawScore` keeps them). Never run by an agent on its own — accepting is how a real gap disappears from view.").addCommand(new Command("add").description("Accept every finding in a scope. Scope = --check and/or --id, narrowed by --page and --match. No --page = every page.").option("--check <name>", "Check name (meta-seo-parity) or module (network)").option("--id <issueId>", "One issue id (only stable ids are worth accepting)").option("--page <key>", "Only this page key, e.g. /::desktop").option("--match <text>", "Only findings whose summary/details contain this (case-insensitive)").requiredOption("--note <why>", "Why the difference is accepted — required").action((opts) => {
|
|
124459
124800
|
process.exit(acceptAdd(opts));
|
|
124460
124801
|
})).addCommand(new Command("list").description("List recorded acceptances with their index").action(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/parity",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.25",
|
|
4
4
|
"description": "E2E parity validator for site migrations. Compares prod vs cand and reports UI, functional, SEO, visual, and Web Vitals deltas with a ranked HTML report.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|