cdk-real-drift 0.19.2 → 0.20.0

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
@@ -15377,6 +15377,7 @@ function redactedHashOf(sentinelOrCanonical) {
15377
15377
 
15378
15378
  //#endregion
15379
15379
  //#region src/baseline/baseline-file.ts
15380
+ const OBSERVED_DEFAULT_TRACKED_PATHS = { "AWS::S3::Bucket": ["PublicAccessBlockConfiguration"] };
15380
15381
  const KNOWN_BASELINE_KEYS = new Set([
15381
15382
  "schemaVersion",
15382
15383
  "stackName",
@@ -15387,7 +15388,8 @@ const KNOWN_BASELINE_KEYS = new Set([
15387
15388
  "recorded",
15388
15389
  "completeResources",
15389
15390
  "recordedPhysicalIds",
15390
- "recordedSourceFingerprints"
15391
+ "recordedSourceFingerprints",
15392
+ "observedDefaults"
15391
15393
  ]);
15392
15394
  const KNOWN_RECORDED_ENTRY_KEYS = new Set([
15393
15395
  "logicalId",
@@ -15448,6 +15450,7 @@ async function loadBaseline(stackName, accountId, region) {
15448
15450
  validateCompleteResources(parsed.completeResources, path);
15449
15451
  validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
15450
15452
  validateRecordedSourceFingerprints(parsed.recordedSourceFingerprints, path);
15453
+ validateObservedDefaults(parsed.observedDefaults, path);
15451
15454
  return parsed;
15452
15455
  }
15453
15456
  /**
@@ -15538,6 +15541,29 @@ function validateRecordedSourceFingerprints(value, path) {
15538
15541
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${at} must be an object mapping "<logicalId>::<path>" to a fingerprint`);
15539
15542
  for (const [key, v] of Object.entries(value)) if (typeof v !== "string") throw new Error(`${at}: "${key}" must map to a string`);
15540
15543
  }
15544
+ /**
15545
+ * #1637: validate `observedDefaults` (optional). When present it must be an array of
15546
+ * { logicalId, resourceType, path } string triples with no unknown keys — the same
15547
+ * loud-vs-silent principle as validateRecordedEntry (a typo'd key silently disables the
15548
+ * vanish detection this field exists to drive). No `value` field by design: the restore
15549
+ * value is the KNOWN_DEFAULTS pin.
15550
+ */
15551
+ function validateObservedDefaults(value, path) {
15552
+ if (value === void 0) return;
15553
+ const at = `baseline file ${path}: \`observedDefaults\``;
15554
+ if (!Array.isArray(value)) throw new Error(`${at} must be an array of { logicalId, resourceType, path }`);
15555
+ value.forEach((entry, i) => {
15556
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(`${at}[${i}] must be an object { logicalId, resourceType, path }`);
15557
+ const obj = entry;
15558
+ for (const k of [
15559
+ "logicalId",
15560
+ "resourceType",
15561
+ "path"
15562
+ ]) if (typeof obj[k] !== "string") throw new Error(`${at}[${i}]: "${k}" is required and must be a string`);
15563
+ const unknown = Object.keys(obj).filter((k) => k !== "logicalId" && k !== "resourceType" && k !== "path");
15564
+ if (unknown.length > 0) throw new Error(`${at}[${i}]: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "logicalId", "resourceType", "path"`);
15565
+ });
15566
+ }
15541
15567
  /** Deterministic order for `recorded` entries: lexicographic by (logicalId, path).
15542
15568
  * The single point where order is imposed — read/compare logic is order-independent,
15543
15569
  * so this only affects the bytes on disk. Without it the entries inherit findings
@@ -15574,7 +15600,8 @@ async function writeBaselineFile(b) {
15574
15600
  recorded: sortRecorded(b.recorded),
15575
15601
  ...b.completeResources ? { completeResources: [...b.completeResources].sort() } : {},
15576
15602
  ...b.recordedPhysicalIds ? { recordedPhysicalIds: sortedPhysicalIds(b.recordedPhysicalIds, b.recorded, b.completeResources ?? []) } : {},
15577
- ...b.recordedSourceFingerprints ? { recordedSourceFingerprints: sortedSourceFingerprints(b.recordedSourceFingerprints, b.recorded) } : {}
15603
+ ...b.recordedSourceFingerprints ? { recordedSourceFingerprints: sortedSourceFingerprints(b.recordedSourceFingerprints, b.recorded) } : {},
15604
+ ...b.observedDefaults && b.observedDefaults.length > 0 ? { observedDefaults: [...b.observedDefaults].sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.path < c.path ? -1 : a.path > c.path ? 1 : 0)) } : {}
15578
15605
  };
15579
15606
  await writeFile(p, JSON.stringify(stable, null, 2) + "\n", "utf8");
15580
15607
  return p;
@@ -15645,12 +15672,47 @@ async function writeBaseline(stackName, region, accountId, findings, rawTemplate
15645
15672
  recorded,
15646
15673
  completeResources,
15647
15674
  ...buildRecordedPhysicalIds(recorded, completeResources, opts.physicalIdByLogical, opts.previous),
15648
- ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous)
15675
+ ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous),
15676
+ ...buildObservedDefaults(findings, opts.previous)
15649
15677
  }),
15650
15678
  count: recorded.length
15651
15679
  };
15652
15680
  }
15653
15681
  /**
15682
+ * #1637: build the `observedDefaults` entries for this record run. Seeds from THIS run's
15683
+ * `atDefault` findings on the curated OBSERVED_DEFAULT_TRACKED_PATHS, then carries forward
15684
+ * the previous baseline's entries for resources this run could NOT observe (a `skipped`
15685
+ * finding — unread, symmetric with carryForwardUnreadable), so a transient read failure
15686
+ * never silently drops the watch. A resource READ this run whose tracked value is ABSENT
15687
+ * (already vanished, or a legacy resource that never had it) is deliberately NOT observed —
15688
+ * re-recording ACCEPTS the current state, exactly like the recorded-value flow. Returns
15689
+ * `{}` (spread to nothing) when empty so old-shaped baselines stay byte-identical.
15690
+ */
15691
+ function buildObservedDefaults(findings, previous) {
15692
+ const out = [];
15693
+ const seen = /* @__PURE__ */ new Set();
15694
+ for (const f of findings) {
15695
+ if (f.tier !== "atDefault") continue;
15696
+ if (!OBSERVED_DEFAULT_TRACKED_PATHS[f.resourceType]?.includes(f.path)) continue;
15697
+ const key = `${f.logicalId}\0${f.path}`;
15698
+ if (seen.has(key)) continue;
15699
+ seen.add(key);
15700
+ out.push({
15701
+ logicalId: f.logicalId,
15702
+ resourceType: f.resourceType,
15703
+ path: f.path
15704
+ });
15705
+ }
15706
+ const skipped = new Set(findings.filter((f) => f.tier === "skipped").map((f) => f.logicalId));
15707
+ for (const o of previous?.observedDefaults ?? []) {
15708
+ const key = `${o.logicalId}\0${o.path}`;
15709
+ if (seen.has(key) || !skipped.has(o.logicalId)) continue;
15710
+ seen.add(key);
15711
+ out.push(o);
15712
+ }
15713
+ return out.length > 0 ? { observedDefaults: out } : {};
15714
+ }
15715
+ /**
15654
15716
  * #674/#792: build the `recordedPhysicalIds` map (logicalId -> physical id) for the
15655
15717
  * resources being written. Covers every RECORDED logicalId PLUS every snapshot-`complete`
15656
15718
  * resource — the latter so a resource recorded as complete but with ZERO undeclared
@@ -16268,6 +16330,31 @@ function applyBaseline(findings, baseline, opts = {}) {
16268
16330
  note: "baseline value removed since record"
16269
16331
  });
16270
16332
  }
16333
+ const readGapLogical = new Set(findings.filter((f) => f.tier === "readGap").map((f) => f.logicalId));
16334
+ for (const o of baseline.observedDefaults ?? []) {
16335
+ if (currentPaths.has(`${o.logicalId}.${o.path}`)) continue;
16336
+ if (recorded.some((a) => a.logicalId === o.logicalId && a.path === o.path && a.resourceType === o.resourceType)) continue;
16337
+ if (skippedLogical.has(o.logicalId)) continue;
16338
+ if (deletedLogical.has(o.logicalId)) continue;
16339
+ if (!readParentLogical.has(o.logicalId)) continue;
16340
+ if (readGapLogical.has(o.logicalId)) continue;
16341
+ if (isTypeVoid(o)) continue;
16342
+ if (replacedLogical.has(o.logicalId)) continue;
16343
+ if (currentLogicalIds !== void 0 && !currentLogicalIds.has(o.logicalId)) continue;
16344
+ if (underDeclaredDrift(o.logicalId, o.path)) continue;
16345
+ if (declaredPathIsPromoted(opts.declaredByLogical?.get(o.logicalId), o.path)) continue;
16346
+ kept.push({
16347
+ tier: "undeclared",
16348
+ logicalId: o.logicalId,
16349
+ resourceType: o.resourceType,
16350
+ ...opts.constructPathByLogical?.get(o.logicalId) !== void 0 && { constructPath: opts.constructPathByLogical.get(o.logicalId) },
16351
+ ...opts.physicalIdByLogical?.get(o.logicalId) !== void 0 && { physicalId: opts.physicalIdByLogical.get(o.logicalId) },
16352
+ path: o.path,
16353
+ desired: KNOWN_DEFAULTS[o.resourceType]?.[o.path],
16354
+ actual: void 0,
16355
+ note: "observed default deleted since record (the whole value vanished from the live read)"
16356
+ });
16357
+ }
16271
16358
  if (promotedStale.length > 0) opts.warn?.(formatPromotedStaleNote(promotedStale));
16272
16359
  if (removedFromTemplate.length > 0) opts.warn?.(formatRemovedFromTemplateNote(removedFromTemplate));
16273
16360
  if (replacedStale.length > 0) opts.warn?.(formatReplacedStaleNote(replacedStale));