cdk-real-drift 0.2.53 → 0.2.54

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
@@ -9059,8 +9059,56 @@ async function loadBaseline(stackName, accountId, region) {
9059
9059
  delete parsed.accepted;
9060
9060
  if (typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 2) throw new Error(`baseline file ${path} was written by a newer cdkrd (schemaVersion ${parsed.schemaVersion}); upgrade cdkrd`);
9061
9061
  if (!Array.isArray(parsed.recorded)) throw new Error(`baseline file ${path} is malformed: \`recorded\` is missing or not an array`);
9062
+ parsed.recorded.forEach((entry, i) => validateRecordedEntry(entry, i, path));
9063
+ validateCompleteResources(parsed.completeResources, path);
9064
+ validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
9062
9065
  return parsed;
9063
9066
  }
9067
+ /**
9068
+ * #794: validate one `recorded` array element. Each must be a non-null object with a
9069
+ * string `logicalId` and a string `path` (the two fields the match logic reads —
9070
+ * `recorded.find(a => a.logicalId === … && a.path === …)`), plus a string `resourceType`
9071
+ * (used for the #793 type-mismatch guard and stamped onto the synthetic removed-since-record
9072
+ * finding). `value` is intentionally unconstrained (any JSON is a valid recorded value,
9073
+ * including `null`). Errors name the file + the offending index/key, mirroring the
9074
+ * ignore.yaml validation style.
9075
+ */
9076
+ function validateRecordedEntry(entry, index, path) {
9077
+ const at = `baseline file ${path}: \`recorded\`[${index}]`;
9078
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(`${at} must be an object { logicalId, resourceType, path, value }`);
9079
+ const obj = entry;
9080
+ for (const k of [
9081
+ "logicalId",
9082
+ "resourceType",
9083
+ "path"
9084
+ ]) if (typeof obj[k] !== "string") throw new Error(`${at}: "${k}" is required and must be a string`);
9085
+ }
9086
+ /**
9087
+ * #794: validate `completeResources` (optional; absent on v1 files). When present it must
9088
+ * be an array of strings — a bare string would have `new Set(...)` iterate its CHARACTERS
9089
+ * (silently mis-scoping completeness), and a number would crash with an opaque
9090
+ * "not iterable" later. Reject both loudly, naming the file + index.
9091
+ */
9092
+ function validateCompleteResources(value, path) {
9093
+ if (value === void 0) return;
9094
+ const at = `baseline file ${path}: \`completeResources\``;
9095
+ if (!Array.isArray(value)) throw new Error(`${at} must be an array of strings`);
9096
+ value.forEach((v, i) => {
9097
+ if (typeof v !== "string") throw new Error(`${at}[${i}] must be a string`);
9098
+ });
9099
+ }
9100
+ /**
9101
+ * #794: validate `recordedPhysicalIds` (optional; #674). When present it must be a plain
9102
+ * object mapping string logicalId -> string physical id — `Object.entries` on a non-object
9103
+ * or a non-string value would otherwise mis-drive the #674 replacement check silently.
9104
+ * Reject non-object shapes and non-string values loudly, naming the file + key.
9105
+ */
9106
+ function validateRecordedPhysicalIds(value, path) {
9107
+ if (value === void 0) return;
9108
+ const at = `baseline file ${path}: \`recordedPhysicalIds\``;
9109
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${at} must be an object mapping logicalId to physical id`);
9110
+ for (const [key, v] of Object.entries(value)) if (typeof v !== "string") throw new Error(`${at}: "${key}" must map to a string`);
9111
+ }
9064
9112
  /** Deterministic order for `recorded` entries: lexicographic by (logicalId, path).
9065
9113
  * The single point where order is imposed — read/compare logic is order-independent,
9066
9114
  * so this only affects the bytes on disk. Without it the entries inherit findings
@@ -9308,7 +9356,7 @@ function splitRecordedByBaseline(recorded, baseline) {
9308
9356
  const unchanged = [];
9309
9357
  const changed = [];
9310
9358
  for (const entry of recorded) {
9311
- const baselineEntry = baseline.recorded.find((a) => a.logicalId === entry.logicalId && a.path === entry.path);
9359
+ const baselineEntry = baseline.recorded.find((a) => a.logicalId === entry.logicalId && a.path === entry.path && a.resourceType === entry.resourceType);
9312
9360
  if (baselineEntry && baselineValueMatches(baselineEntry.value, entry.value)) unchanged.push(entry);
9313
9361
  else changed.push(entry);
9314
9362
  }
@@ -9354,9 +9402,16 @@ function applyBaseline(findings, baseline, opts = {}) {
9354
9402
  const liveId = opts.physicalIdByLogical?.get(logicalId);
9355
9403
  if (liveId !== void 0 && liveId !== recordedId) replacedLogical.add(logicalId);
9356
9404
  }
9405
+ const liveTypeByLogical = /* @__PURE__ */ new Map();
9406
+ for (const f of findings) if (f.resourceType) liveTypeByLogical.set(f.logicalId, f.resourceType);
9407
+ const isTypeVoid = (e) => {
9408
+ const liveType = liveTypeByLogical.get(e.logicalId);
9409
+ return liveType !== void 0 && liveType !== e.resourceType;
9410
+ };
9411
+ const entryMatches = (a, f) => a.logicalId === f.logicalId && a.path === f.path && a.resourceType === f.resourceType;
9357
9412
  for (const f of findings) {
9358
9413
  if (f.tier === "added") {
9359
- const entry = recorded.find((a) => a.logicalId === f.logicalId && a.path === f.path);
9414
+ const entry = recorded.find((a) => entryMatches(a, f));
9360
9415
  if (f.modelReadFailed) {
9361
9416
  if (entry) continue;
9362
9417
  kept.push({
@@ -9384,7 +9439,7 @@ function applyBaseline(findings, baseline, opts = {}) {
9384
9439
  kept.push(f);
9385
9440
  continue;
9386
9441
  }
9387
- const entry = replacedLogical.has(f.logicalId) ? void 0 : recorded.find((a) => a.logicalId === f.logicalId && a.path === f.path);
9442
+ const entry = replacedLogical.has(f.logicalId) ? void 0 : recorded.find((a) => entryMatches(a, f));
9388
9443
  if (entry && baselineValueMatches(entry.value, f.actual)) continue;
9389
9444
  if (entry) {
9390
9445
  const delta = identityArrayDelta(canonicalizeForCompare(entry.value), f.actual);
@@ -9422,8 +9477,13 @@ function applyBaseline(findings, baseline, opts = {}) {
9422
9477
  const promotedStale = [];
9423
9478
  const removedFromTemplate = [];
9424
9479
  const replacedStale = [];
9480
+ const typeMismatchStale = [];
9425
9481
  for (const a of recorded) {
9426
9482
  if (a.path === "") continue;
9483
+ if (isTypeVoid(a)) {
9484
+ typeMismatchStale.push(`${a.logicalId}.${a.path}`);
9485
+ continue;
9486
+ }
9427
9487
  if (replacedLogical.has(a.logicalId)) {
9428
9488
  replacedStale.push(`${a.logicalId}.${a.path}`);
9429
9489
  continue;
@@ -9455,6 +9515,7 @@ function applyBaseline(findings, baseline, opts = {}) {
9455
9515
  if (promotedStale.length > 0) opts.warn?.(formatPromotedStaleNote(promotedStale));
9456
9516
  if (removedFromTemplate.length > 0) opts.warn?.(formatRemovedFromTemplateNote(removedFromTemplate));
9457
9517
  if (replacedStale.length > 0) opts.warn?.(formatReplacedStaleNote(replacedStale));
9518
+ if (typeMismatchStale.length > 0) opts.warn?.(formatTypeMismatchStaleNote(typeMismatchStale));
9458
9519
  return kept;
9459
9520
  }
9460
9521
  /**
@@ -9484,6 +9545,16 @@ function formatReplacedStaleNote(paths) {
9484
9545
  const n = paths.length;
9485
9546
  return `note: ${n === 1 ? `baseline entry (${paths[0]}) was` : `${n} baseline entries were`} recorded against a resource since REPLACED by a deploy — re-run \`cdkrd record\`.`;
9486
9547
  }
9548
+ /**
9549
+ * #793: the folded one-line note for baseline entries whose logicalId now hosts a resource
9550
+ * of a DIFFERENT type (the id was recycled across a template refactor). The old-type entries
9551
+ * are void against the new resource. Mirror of formatReplacedStaleNote. Pure + exported for
9552
+ * unit tests.
9553
+ */
9554
+ function formatTypeMismatchStaleNote(paths) {
9555
+ const n = paths.length;
9556
+ return `note: ${n === 1 ? `baseline entry (${paths[0]}) was` : `${n} baseline entries were`} recorded against a resource whose logicalId now has a DIFFERENT type — re-run \`cdkrd record\`.`;
9557
+ }
9487
9558
  /** logicalId -> set of declared top-level keys, for applyBaseline's promotion check. */
9488
9559
  function declaredKeysByLogical(resources) {
9489
9560
  return new Map(resources.map((r) => [r.logicalId, new Set(Object.keys(r.declared))]));