@decocms/parity 0.35.20 → 0.35.21

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.
Files changed (2) hide show
  1. package/dist/cli.js +264 -19
  2. package/package.json +1 -1
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 chalk47 from "chalk";
75782
+ import chalk48 from "chalk";
75783
75783
  import { Command, InvalidArgumentError as InvalidArgumentError2 } from "commander";
75784
75784
 
75785
75785
  // src/commands/ab-detect.ts
@@ -121590,8 +121590,243 @@ async function studioCommentCommand(opts, call = callTool2) {
121590
121590
  }
121591
121591
  }
121592
121592
 
121593
- // src/commands/variance.ts
121593
+ // src/commands/drift.ts
121594
+ import { spawnSync as spawnSync3 } from "node:child_process";
121595
+ import { existsSync as existsSync38, readFileSync as readFileSync44 } from "node:fs";
121596
+ import { resolve as resolve22 } from "node:path";
121594
121597
  import chalk45 from "chalk";
121598
+ var DRIFT_EXCLUDES = [":!.deco"];
121599
+ var SHA_RE = /^[0-9a-f]{7,64}$/i;
121600
+ function resolveDriftInputs(state, flags) {
121601
+ const src = state?.source;
121602
+ let source = flags.source;
121603
+ if (!source) {
121604
+ if (!state) {
121605
+ return {
121606
+ error: {
121607
+ code: "no_state",
121608
+ message: "no state file and no --source/--base given, so there is nothing to compare"
121609
+ }
121610
+ };
121611
+ }
121612
+ if (src?.kind === "live-only") {
121613
+ return {
121614
+ error: {
121615
+ code: "live_only",
121616
+ message: "source.kind is live-only: there is no source repo, so there are no source commits to count. Re-run `parity run` against prod instead (the weaker check)"
121617
+ }
121618
+ };
121619
+ }
121620
+ if (!src?.repo) {
121621
+ return { error: { code: "no_source", message: "source.repo is not set in the state file" } };
121622
+ }
121623
+ source = src.repo;
121624
+ }
121625
+ let base = flags.base;
121626
+ let baseFrom = "flag";
121627
+ if (!base) {
121628
+ if (src?.reconciledTo?.sha) {
121629
+ base = src.reconciledTo.sha;
121630
+ baseFrom = "reconciledTo";
121631
+ } else if (src?.snapshot?.sha) {
121632
+ base = src.snapshot.sha;
121633
+ baseFrom = "snapshot";
121634
+ }
121635
+ }
121636
+ if (!base) {
121637
+ return {
121638
+ error: {
121639
+ code: "no_base",
121640
+ message: "no base commit: pass --base, or the state file has neither source.reconciledTo.sha nor source.snapshot.sha (the cut was never recorded)"
121641
+ }
121642
+ };
121643
+ }
121644
+ if (!SHA_RE.test(base)) {
121645
+ return { error: { code: "bad_base", message: `base "${base}" is not a commit SHA` } };
121646
+ }
121647
+ return { source, base, baseFrom };
121648
+ }
121649
+ function parseCommitLog(stdout) {
121650
+ const out = [];
121651
+ for (const rec of stdout.split("\x1E")) {
121652
+ const r = rec.replace(/^\n+/, "");
121653
+ if (!r.trim())
121654
+ continue;
121655
+ const [sha = "", author = "", date = "", ...subject] = r.split("\x1F");
121656
+ if (sha)
121657
+ out.push({ sha, author, date, subject: subject.join("\x1F").trim() });
121658
+ }
121659
+ return out;
121660
+ }
121661
+ var WRAPPER_DIRS = new Set(["src", "packages", "apps"]);
121662
+ function groupOf(path) {
121663
+ const seg = path.split("/");
121664
+ if (seg.length === 1)
121665
+ return "(root)";
121666
+ if (WRAPPER_DIRS.has(seg[0]) && seg.length > 2)
121667
+ return `${seg[0]}/${seg[1]}`;
121668
+ return seg[0];
121669
+ }
121670
+ function parseNameStatus(stdout) {
121671
+ const out = [];
121672
+ for (const line of stdout.split(`
121673
+ `)) {
121674
+ if (!line.trim())
121675
+ continue;
121676
+ const parts = line.split("\t");
121677
+ const status = (parts[0] ?? "").charAt(0);
121678
+ if (!status)
121679
+ continue;
121680
+ if ((status === "R" || status === "C") && parts.length >= 3) {
121681
+ out.push({
121682
+ path: parts[2],
121683
+ status,
121684
+ oldPath: parts[1],
121685
+ group: groupOf(parts[2])
121686
+ });
121687
+ } else if (parts[1]) {
121688
+ out.push({ path: parts[1], status, group: groupOf(parts[1]) });
121689
+ }
121690
+ }
121691
+ return out;
121692
+ }
121693
+ function groupFiles(files) {
121694
+ const m = new Map;
121695
+ for (const f of files)
121696
+ m.set(f.group, (m.get(f.group) ?? 0) + 1);
121697
+ return [...m.entries()].map(([group, files]) => ({ group, files })).sort((a, b) => b.files - a.files || a.group.localeCompare(b.group));
121698
+ }
121699
+ function git(source, args) {
121700
+ const r = spawnSync3("git", ["-C", source, "-c", "core.quotepath=false", ...args], {
121701
+ encoding: "utf8",
121702
+ maxBuffer: 256 * 1024 * 1024
121703
+ });
121704
+ if (r.error || r.status !== 0) {
121705
+ return { ok: false, stderr: (r.error?.message ?? r.stderr ?? "").trim() };
121706
+ }
121707
+ return { ok: true, stdout: r.stdout };
121708
+ }
121709
+ function computeDrift(inputs, opts) {
121710
+ const { source, base, baseFrom } = inputs;
121711
+ const headRef = opts.head ?? "@{upstream}";
121712
+ const fail = (code, message) => ({ error: { code, message } });
121713
+ if (headRef.startsWith("-"))
121714
+ return fail("bad_head", `head "${headRef}" looks like a flag`);
121715
+ if (!existsSync38(source))
121716
+ return fail("not_a_repo", `${source} does not exist`);
121717
+ const inside = git(source, ["rev-parse", "--is-inside-work-tree"]);
121718
+ if (!inside.ok || inside.stdout.trim() !== "true") {
121719
+ return fail("not_a_repo", `${source} is not a git work tree`);
121720
+ }
121721
+ const doFetch = opts.fetch !== false;
121722
+ if (doFetch) {
121723
+ const f = git(source, ["fetch", "--quiet"]);
121724
+ if (!f.ok) {
121725
+ return fail("fetch_failed", `git fetch failed (${f.stderr || "no output"}); pass --no-fetch to measure against what is already local`);
121726
+ }
121727
+ }
121728
+ const head = git(source, ["rev-parse", "--verify", "--end-of-options", `${headRef}^{commit}`]);
121729
+ if (!head.ok) {
121730
+ return headRef === "@{upstream}" ? fail("no_upstream", `the current branch of ${source} has no upstream to compare against`) : fail("head_not_found", `${headRef} does not resolve to a commit in ${source}`);
121731
+ }
121732
+ const headSha = head.stdout.trim();
121733
+ const b = git(source, ["rev-parse", "--verify", "--end-of-options", `${base}^{commit}`]);
121734
+ if (!b.ok) {
121735
+ return fail("base_not_found", `base ${base} is not a commit in ${source}; the clone may be shallow or a different repo`);
121736
+ }
121737
+ const baseSha = b.stdout.trim();
121738
+ const anc = spawnSync3("git", ["-C", source, "merge-base", "--is-ancestor", baseSha, headSha]);
121739
+ if (anc.status === 1) {
121740
+ return fail("base_not_ancestor", `base ${base} is not an ancestor of ${headRef} (history rewritten?)`);
121741
+ }
121742
+ if (anc.status !== 0)
121743
+ return fail("git_failed", `git merge-base failed: ${anc.stderr?.toString().trim()}`);
121744
+ const range = `${baseSha}..${headSha}`;
121745
+ const log = git(source, [
121746
+ "log",
121747
+ "--format=%H%x1f%an%x1f%aI%x1f%s%x1e",
121748
+ range,
121749
+ "--",
121750
+ ".",
121751
+ ...DRIFT_EXCLUDES
121752
+ ]);
121753
+ if (!log.ok)
121754
+ return fail("git_failed", `git log failed: ${log.stderr}`);
121755
+ const diff = git(source, [
121756
+ "diff",
121757
+ "--name-status",
121758
+ "-M",
121759
+ baseSha,
121760
+ headSha,
121761
+ "--",
121762
+ ".",
121763
+ ...DRIFT_EXCLUDES
121764
+ ]);
121765
+ if (!diff.ok)
121766
+ return fail("git_failed", `git diff failed: ${diff.stderr}`);
121767
+ const commitList = parseCommitLog(log.stdout);
121768
+ const files = parseNameStatus(diff.stdout);
121769
+ return {
121770
+ source,
121771
+ base,
121772
+ baseFrom,
121773
+ head: { ref: headRef, sha: headSha },
121774
+ commits: commitList.length,
121775
+ commitList,
121776
+ files,
121777
+ groups: groupFiles(files),
121778
+ excluded: [...DRIFT_EXCLUDES],
121779
+ fetched: doFetch
121780
+ };
121781
+ }
121782
+ function loadState(path) {
121783
+ if (!existsSync38(path))
121784
+ return null;
121785
+ try {
121786
+ return JSON.parse(readFileSync44(path, "utf8"));
121787
+ } catch (err) {
121788
+ return { error: { code: "state_unreadable", message: `${path}: ${err.message}` } };
121789
+ }
121790
+ }
121791
+ function runDrift(flags) {
121792
+ let state = null;
121793
+ if (!(flags.source && flags.base)) {
121794
+ const loaded = loadState(resolve22(flags.state ?? ".parity/migration.json"));
121795
+ if (loaded && "error" in loaded)
121796
+ return loaded;
121797
+ state = loaded;
121798
+ }
121799
+ const inputs = resolveDriftInputs(state, flags);
121800
+ if ("error" in inputs)
121801
+ return inputs;
121802
+ return computeDrift(inputs, { head: flags.head, fetch: flags.fetch });
121803
+ }
121804
+ function driftCommand(flags) {
121805
+ const r = runDrift(flags);
121806
+ if ("error" in r) {
121807
+ if (flags.json)
121808
+ console.log(JSON.stringify({ error: r.error }));
121809
+ else
121810
+ console.error(chalk45.red(` could not measure drift [${r.error.code}]: ${r.error.message}`));
121811
+ return 2;
121812
+ }
121813
+ if (flags.json) {
121814
+ console.log(JSON.stringify(r));
121815
+ } else {
121816
+ const base = `${r.base.slice(0, 7)} (${r.baseFrom})`;
121817
+ console.log(` source ${r.source}`);
121818
+ console.log(` range ${base} .. ${r.head.sha.slice(0, 7)} (${r.head.ref})`);
121819
+ console.log(` drift ${r.commits} commit(s), ${r.files.length} file(s)${r.fetched ? "" : " [not fetched]"}`);
121820
+ for (const g of r.groups)
121821
+ console.log(` ${String(g.files).padStart(4)} ${g.group}`);
121822
+ for (const c of r.commitList)
121823
+ console.log(` ${c.sha.slice(0, 7)} ${c.subject}`);
121824
+ }
121825
+ return r.commits > 0 ? 1 : 0;
121826
+ }
121827
+
121828
+ // src/commands/variance.ts
121829
+ import chalk46 from "chalk";
121595
121830
 
121596
121831
  // src/diff/variance.ts
121597
121832
  var uniq2 = (xs) => [...new Set(xs)];
@@ -121695,7 +121930,7 @@ function formatVariance(report, opts = {}) {
121695
121930
  // src/commands/variance.ts
121696
121931
  function varianceCommand(opts) {
121697
121932
  if (opts.runIds.length < 2) {
121698
- console.error(chalk45.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
121933
+ console.error(chalk46.red(" informe pelo menos 2 runs: parity variance <runIdA> <runIdB> [...]"));
121699
121934
  return 2;
121700
121935
  }
121701
121936
  const budget = Number.parseFloat(opts.scoreBudget ?? "1");
@@ -121704,7 +121939,7 @@ function varianceCommand(opts) {
121704
121939
  try {
121705
121940
  runs.push(loadRun(opts.output, id));
121706
121941
  } catch (err) {
121707
- console.error(chalk45.red(` ✖ ${err.message}`));
121942
+ console.error(chalk46.red(` ✖ ${err.message}`));
121708
121943
  return 2;
121709
121944
  }
121710
121945
  }
@@ -121713,7 +121948,7 @@ function varianceCommand(opts) {
121713
121948
  console.log(JSON.stringify({ ...report, stable: isStable(report, budget), scoreBudget: budget }));
121714
121949
  } else {
121715
121950
  console.log("");
121716
- console.log(chalk45.bold(" Score variance"));
121951
+ console.log(chalk46.bold(" Score variance"));
121717
121952
  for (const line of formatVariance(report, { scoreBudget: budget }).split(`
121718
121953
  `)) {
121719
121954
  console.log(` ${line}`);
@@ -121725,10 +121960,10 @@ function varianceCommand(opts) {
121725
121960
  }
121726
121961
 
121727
121962
  // src/commands/vitals.ts
121728
- import { existsSync as existsSync38, readFileSync as readFileSync44, writeFileSync as writeFileSync37 } from "node:fs";
121963
+ import { existsSync as existsSync39, readFileSync as readFileSync45, writeFileSync as writeFileSync37 } from "node:fs";
121729
121964
  import { availableParallelism } from "node:os";
121730
121965
  import { join as join51 } from "node:path";
121731
- import chalk46 from "chalk";
121966
+ import chalk47 from "chalk";
121732
121967
  import ora9 from "ora";
121733
121968
 
121734
121969
  // src/checks/agentic-nav.ts
@@ -122026,10 +122261,10 @@ async function vitalsCommand(opts) {
122026
122261
  const runId = newRunId();
122027
122262
  const paths = createRunDir(opts.output, runId);
122028
122263
  const t0 = Date.now();
122029
- console.log(chalk46.bold(`
122264
+ console.log(chalk47.bold(`
122030
122265
  parity vitals ${runId}`));
122031
- console.log(chalk46.dim(` prod: ${opts.prod}`));
122032
- console.log(chalk46.dim(` cand: ${opts.cand}`));
122266
+ console.log(chalk47.dim(` prod: ${opts.prod}`));
122267
+ console.log(chalk47.dim(` cand: ${opts.cand}`));
122033
122268
  const discoverSpinner = ora9("Descobrindo páginas…").start();
122034
122269
  const pagePaths = await discoverPagePaths2(opts.prod, opts);
122035
122270
  if (pagePaths.length === 0) {
@@ -122061,7 +122296,7 @@ async function vitalsCommand(opts) {
122061
122296
  completed++;
122062
122297
  const elapsed = ((Date.now() - t0) / 1000).toFixed(0);
122063
122298
  const etaSec = completed > 0 ? Math.round((Date.now() - t0) / completed * (total - completed) / 1000) : 0;
122064
- progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk46.cyan("prod") : chalk46.magenta("cand")} ${task.path} (${task.viewport})`;
122299
+ progress.text = `${completed}/${total} · ${elapsed}s · ETA ${etaSec}s · ${task.side === "prod" ? chalk47.cyan("prod") : chalk47.magenta("cand")} ${task.path} (${task.viewport})`;
122065
122300
  }
122066
122301
  });
122067
122302
  progress.succeed(`${total} capture(s) em ${((Date.now() - t0) / 1000).toFixed(1)}s`);
@@ -122090,7 +122325,7 @@ async function vitalsCommand(opts) {
122090
122325
  }
122091
122326
  lhCompleted++;
122092
122327
  const elapsed = ((Date.now() - lhT0) / 1000).toFixed(0);
122093
- lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk46.cyan("prod") : chalk46.magenta("cand")} ${task.path} (${task.viewport})`;
122328
+ lhProgress.text = `Lighthouse ${lhCompleted}/${done.length} · ${elapsed}s · ${task.side === "prod" ? chalk47.cyan("prod") : chalk47.magenta("cand")} ${task.path} (${task.viewport})`;
122094
122329
  });
122095
122330
  lhProgress.succeed(`Lighthouse ${done.length} página(s) em ${((Date.now() - lhT0) / 1000).toFixed(1)}s`);
122096
122331
  }
@@ -122168,8 +122403,8 @@ async function vitalsCommand(opts) {
122168
122403
  `, "utf8");
122169
122404
  printSummary9(vitalsResult, cacheResult, scoresResult, oppsResult, agenticResult);
122170
122405
  console.log("");
122171
- console.log(chalk46.dim(` → ${paths.reportHtml}`));
122172
- console.log(chalk46.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
122406
+ console.log(chalk47.dim(` → ${paths.reportHtml}`));
122407
+ console.log(chalk47.dim(` \uD83D\uDCA1 use 'parity serve ${runId}' pra preview iframe`));
122173
122408
  console.log("");
122174
122409
  if (opts.open) {
122175
122410
  const { default: open } = await import("open");
@@ -122261,15 +122496,15 @@ async function discoverPagePaths2(prodUrl, opts) {
122261
122496
  function parseUrlList(input) {
122262
122497
  if (input.startsWith("file:") || input.endsWith(".txt") || input.endsWith(".list")) {
122263
122498
  const path = input.replace(/^file:\/\//, "");
122264
- if (existsSync38(path)) {
122265
- return readFileSync44(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
122499
+ if (existsSync39(path)) {
122500
+ return readFileSync45(path, "utf8").split(/\r?\n/).map((s) => s.trim()).filter((s) => s && !s.startsWith("#")).map((s) => s.startsWith("/") ? s : `/${s}`);
122266
122501
  }
122267
122502
  }
122268
122503
  return input.split(",").map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith("/") || s.startsWith("http") ? s : `/${s}`);
122269
122504
  }
122270
122505
  function printSummary9(vitals, cache, scores, opportunities, agentic) {
122271
122506
  console.log("");
122272
- console.log(chalk46.bold(" Summary:"));
122507
+ console.log(chalk47.bold(" Summary:"));
122273
122508
  console.log(` ${vitals.summary}`);
122274
122509
  console.log(` ${cache.summary}`);
122275
122510
  if (scores.status !== "skipped")
@@ -122333,10 +122568,10 @@ sweep.addCommand(new Command("regress").description("Run only the store's tests/
122333
122568
  if (opts.json)
122334
122569
  console.log(JSON.stringify({ url: opts.url, issues }));
122335
122570
  else if (!issues.length)
122336
- console.log(chalk47.green(" regression suite: all passed"));
122571
+ console.log(chalk48.green(" regression suite: all passed"));
122337
122572
  else
122338
122573
  for (const i of issues)
122339
- console.log((i.inconclusive ? chalk47.yellow : chalk47.red)(` ${i.summary}`));
122574
+ console.log((i.inconclusive ? chalk48.yellow : chalk48.red)(` ${i.summary}`));
122340
122575
  process.exit(regressed ? 1 : unverified ? 2 : 0);
122341
122576
  }));
122342
122577
  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) => {
@@ -122677,6 +122912,16 @@ program.command("mcp").description("Expose the migration over MCP on stdio: stat
122677
122912
  allowWrites: opts.allowWrites
122678
122913
  }));
122679
122914
  });
122915
+ program.command("drift").description("How far has the SOURCE repo moved since the migration was cut (or last reconciled)? Reads source.repo and reconciledTo.sha ?? snapshot.sha from .parity/migration.json (flags override), fetches, and reports the commits and changed files since, grouped by path, with `.deco/` excluded. Read-only: never writes the state file. Exits 0 no drift, 1 drift, 2 could not tell (no base, not a git repo, unknown base, no upstream, fetch failed) -- never 0 on a git failure.").option("--source <path>", "Local clone of the source repo (default: source.repo from the state file)").option("--base <sha>", "Commit to measure from (default: reconciledTo.sha, else snapshot.sha)").option("--state <path>", "Migration state file", ".parity/migration.json").option("--head <ref>", "Ref to measure to", "@{upstream}").option("--no-fetch", "Skip `git fetch`; measure against what is already local").option("--json", "Emit one-line JSON instead of text", false).action((opts) => {
122916
+ process.exit(driftCommand({
122917
+ source: opts.source,
122918
+ base: opts.base,
122919
+ state: opts.state,
122920
+ head: opts.head,
122921
+ fetch: opts.fetch,
122922
+ json: opts.json
122923
+ }));
122924
+ });
122680
122925
  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) => {
122681
122926
  process.exit(varianceCommand({
122682
122927
  runIds,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/parity",
3
- "version": "0.35.20",
3
+ "version": "0.35.21",
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",