cdk-real-drift 0.2.57 → 0.2.59

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 CHANGED
@@ -12728,9 +12728,9 @@ const INFO_TIERS = [
12728
12728
  ];
12729
12729
  function formatFinding(f, stackName = "") {
12730
12730
  const id = f.constructPath ? withinStackPath(f.constructPath, stackName) : f.logicalId;
12731
- const pathDisplay = f.attributeKey ? `${f.path}[${f.attributeKey}]` : f.path;
12731
+ const pathDisplay = f.attributeKey ? `${f.path}[${sanitizeForTerminal(f.attributeKey)}]` : f.path;
12732
12732
  let s = `${pathDisplay ? `${id}.${pathDisplay}` : id} (${f.resourceType})`;
12733
- if (f.note) s += ` — ${f.note}`;
12733
+ if (f.note) s += ` — ${sanitizeForTerminal(f.note)}`;
12734
12734
  if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false);
12735
12735
  else {
12736
12736
  const { a: d, b: act } = jPair(f.desired, f.actual);
@@ -12743,7 +12743,7 @@ function formatFinding(f, stackName = "") {
12743
12743
  }
12744
12744
  else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta);
12745
12745
  else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(f.actual))}`;
12746
- if (f.hint) s += `\n ${style.note(`↳ ${f.hint}`)}`;
12746
+ if (f.hint) s += `\n ${style.note(`↳ ${sanitizeForTerminal(f.hint)}`)}`;
12747
12747
  return s;
12748
12748
  }
12749
12749
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -12757,9 +12757,10 @@ function formatMapDelta(desired, actual, baselineLabels) {
12757
12757
  if (inD && Object.hasOwn(actual, k)) {
12758
12758
  if (deepEqual(desired[k], actual[k])) continue;
12759
12759
  const { a, b } = jPair(desired[k], actual[k]);
12760
- s += `\n ~ ${k}\n ${lhs}=${style.desired(a)}\n ${rhs}=${style.actual(b)}`;
12761
- } else if (inD) s += `\n - ${k} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(desired[k]))}`;
12762
- else s += `\n + ${k} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(actual[k]))}`;
12760
+ const sk = sanitizeForTerminal(k);
12761
+ s += `\n ~ ${sk}\n ${lhs}=${style.desired(a)}\n ${rhs}=${style.actual(b)}`;
12762
+ } else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(desired[k]))}`;
12763
+ else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(actual[k]))}`;
12763
12764
  }
12764
12765
  if (s === "") {
12765
12766
  const { a, b } = jPair(desired, actual);
@@ -12770,13 +12771,13 @@ function formatMapDelta(desired, actual, baselineLabels) {
12770
12771
  function formatArrayDelta(d) {
12771
12772
  const baseline = (v) => `\n baseline=${style.desired(j(v))}`;
12772
12773
  const actual = (v) => `\n actual =${style.actual(j(v))}`;
12773
- let s = ` — ${d.identityField}-keyed element(s) changed vs .cdkrd baseline:`;
12774
- for (const a of d.added) s += `\n + [${a.id}]${actual(a.value)}`;
12774
+ let s = ` — ${sanitizeForTerminal(d.identityField)}-keyed element(s) changed vs .cdkrd baseline:`;
12775
+ for (const a of d.added) s += `\n + [${sanitizeForTerminal(a.id)}]${actual(a.value)}`;
12775
12776
  for (const c of d.changed) {
12776
12777
  const { a: base, b: act } = jPair(c.recorded, c.actual);
12777
- s += `\n ~ [${c.id}]\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
12778
+ s += `\n ~ [${sanitizeForTerminal(c.id)}]\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
12778
12779
  }
12779
- for (const r of d.removed) s += `\n - [${r.id}]${baseline(r.value)}`;
12780
+ for (const r of d.removed) s += `\n - [${sanitizeForTerminal(r.id)}]${baseline(r.value)}`;
12780
12781
  return s;
12781
12782
  }
12782
12783
  function tierStyle(t) {
@@ -12919,6 +12920,14 @@ function j(v) {
12919
12920
  const s = JSON.stringify(v);
12920
12921
  return s && s.length > VALUE_CAP ? safeSlice(s, 0, VALUE_CAP) + "…" : s ?? String(v);
12921
12922
  }
12923
+ function sanitizeForTerminal(s) {
12924
+ let out = "";
12925
+ for (const ch of s) {
12926
+ const code = ch.charCodeAt(0);
12927
+ out += code < 32 || code === 127 ? `\\x${code.toString(16).padStart(2, "0")}` : ch;
12928
+ }
12929
+ return out;
12930
+ }
12922
12931
  function jPair(a, b) {
12923
12932
  const as = JSON.stringify(a) ?? String(a);
12924
12933
  const bs = JSON.stringify(b) ?? String(b);
@@ -13452,19 +13461,30 @@ function nestedStackWarning(resources, stackName) {
13452
13461
  const names = nested.map((r) => r.constructPath ? withinStackPath(r.constructPath, stackName) : r.logicalId).sort();
13453
13462
  return `warning: ${stackName} has ${nested.length} nested CloudFormation stack(s) — cdkrd does not recurse into them, so the resources INSIDE them are NOT checked: ${names.join(", ")}`;
13454
13463
  }
13455
- function coverageWarning(findings, stackName) {
13456
- const skipped = findings.filter((f) => f.tier === "skipped");
13464
+ function isPendingCreationSkip(f) {
13465
+ return f.tier === "skipped" && f.note === "no physical id";
13466
+ }
13467
+ function coverageWarning(findings, stackName, preDeploy = false) {
13468
+ const skipped = findings.filter((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f)));
13457
13469
  if (skipped.length === 0) return null;
13458
13470
  const names = skipped.map((f) => f.constructPath ? withinStackPath(f.constructPath, stackName) : f.logicalId).sort();
13459
13471
  const shown = names.slice(0, 10);
13460
13472
  const more = names.length > shown.length ? `, …(+${names.length - shown.length} more)` : "";
13461
13473
  return `warning: ${stackName}: ${skipped.length} resource(s) were NOT checked (coverage incomplete) — ${shown.join(", ")}${more}; see the skipped breakdown (--verbose)`;
13462
13474
  }
13463
- function hasCoverageGap(findings, resources) {
13464
- return findings.some((f) => f.tier === "skipped") || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
13475
+ function pendingCreationInfo(findings, stackName) {
13476
+ const pending = findings.filter(isPendingCreationSkip);
13477
+ if (pending.length === 0) return null;
13478
+ const names = pending.map((f) => f.constructPath ? withinStackPath(f.constructPath, stackName) : f.logicalId).sort();
13479
+ const shown = names.slice(0, 10);
13480
+ const more = names.length > shown.length ? `, …(+${names.length - shown.length} more)` : "";
13481
+ return `info: ${stackName}: ${pending.length} resource(s) not yet deployed — will be created by the next deploy (pending creation, not a coverage gap): ${shown.join(", ")}${more}`;
13482
+ }
13483
+ function hasCoverageGap(findings, resources, preDeploy = false) {
13484
+ return findings.some((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f))) || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
13465
13485
  }
13466
- function strictCoverageExit(strict, findings, resources) {
13467
- return strict && hasCoverageGap(findings, resources) ? 1 : 0;
13486
+ function strictCoverageExit(strict, findings, resources, preDeploy = false) {
13487
+ return strict && hasCoverageGap(findings, resources, preDeploy) ? 1 : 0;
13468
13488
  }
13469
13489
  /**
13470
13490
  * Map a stack's drift code to check's final exit (R53, the `cdk diff --fail` /
@@ -13571,9 +13591,13 @@ async function runCheck(args) {
13571
13591
  const nestedWarn = nestedStackWarning(desired.resources, stackName);
13572
13592
  if (nestedWarn) console.error(nestedWarn);
13573
13593
  if (a.json) {
13574
- const covWarn = coverageWarning(gathered.findings, stackName);
13594
+ const covWarn = coverageWarning(gathered.findings, stackName, a.preDeploy);
13575
13595
  if (covWarn) console.error(covWarn);
13576
13596
  }
13597
+ if (a.preDeploy) {
13598
+ const pendingInfo = pendingCreationInfo(gathered.findings, stackName);
13599
+ if (pendingInfo) console.error(pendingInfo);
13600
+ }
13577
13601
  if (desired.stackStatusWarning) console.error(`warning: ${stackName}: ${desired.stackStatusWarning}`);
13578
13602
  if (a.undeclaredOnly) {
13579
13603
  findings = undeclaredOnlyFindings(findings);
@@ -13601,7 +13625,7 @@ async function runCheck(args) {
13601
13625
  } else preDeployCode = report(preDeployReconciled, preDeployHeader, { verbose: a.verbose });
13602
13626
  if (preDeployCode === 1) anyDrift = true;
13603
13627
  worst = Math.max(worst, finalCheckExit(preDeployCode, a.fail));
13604
- worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
13628
+ worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources, true));
13605
13629
  continue;
13606
13630
  }
13607
13631
  const baseline = a.showAll ? void 0 : await loadBaseline(stackName, desired.accountId, region);