cdk-real-drift 0.19.1 → 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
@@ -5905,7 +5905,16 @@ const MEANINGFUL_WHEN_OFF = {
5905
5905
  "AWS::Redshift::Cluster": { AllowVersionUpgrade: notRestored("SnapshotIdentifier") },
5906
5906
  "AWS::EC2::ClientVpnEndpoint": { DisconnectOnSessionTimeout: () => true },
5907
5907
  "AWS::ImageBuilder::ImagePipeline": { EnhancedImageMetadataEnabled: () => true },
5908
- "AWS::ImageBuilder::InfrastructureConfiguration": { TerminateInstanceOnFailure: () => true }
5908
+ "AWS::ImageBuilder::InfrastructureConfiguration": { TerminateInstanceOnFailure: () => true },
5909
+ "AWS::SES::ConfigurationSet": {
5910
+ SendingOptions: () => true,
5911
+ ReputationOptions: () => true
5912
+ },
5913
+ "AWS::SES::EmailIdentity": {
5914
+ DkimAttributes: () => true,
5915
+ FeedbackAttributes: () => true
5916
+ },
5917
+ "AWS::S3::Bucket": { PublicAccessBlockConfiguration: () => true }
5909
5918
  };
5910
5919
  const MEANINGFUL_WHEN_OFF_NESTED = {
5911
5920
  "AWS::CloudFront::Distribution": { "DistributionConfig.IPV6Enabled": () => true },
@@ -15368,6 +15377,7 @@ function redactedHashOf(sentinelOrCanonical) {
15368
15377
 
15369
15378
  //#endregion
15370
15379
  //#region src/baseline/baseline-file.ts
15380
+ const OBSERVED_DEFAULT_TRACKED_PATHS = { "AWS::S3::Bucket": ["PublicAccessBlockConfiguration"] };
15371
15381
  const KNOWN_BASELINE_KEYS = new Set([
15372
15382
  "schemaVersion",
15373
15383
  "stackName",
@@ -15378,7 +15388,8 @@ const KNOWN_BASELINE_KEYS = new Set([
15378
15388
  "recorded",
15379
15389
  "completeResources",
15380
15390
  "recordedPhysicalIds",
15381
- "recordedSourceFingerprints"
15391
+ "recordedSourceFingerprints",
15392
+ "observedDefaults"
15382
15393
  ]);
15383
15394
  const KNOWN_RECORDED_ENTRY_KEYS = new Set([
15384
15395
  "logicalId",
@@ -15439,6 +15450,7 @@ async function loadBaseline(stackName, accountId, region) {
15439
15450
  validateCompleteResources(parsed.completeResources, path);
15440
15451
  validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
15441
15452
  validateRecordedSourceFingerprints(parsed.recordedSourceFingerprints, path);
15453
+ validateObservedDefaults(parsed.observedDefaults, path);
15442
15454
  return parsed;
15443
15455
  }
15444
15456
  /**
@@ -15529,6 +15541,29 @@ function validateRecordedSourceFingerprints(value, path) {
15529
15541
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${at} must be an object mapping "<logicalId>::<path>" to a fingerprint`);
15530
15542
  for (const [key, v] of Object.entries(value)) if (typeof v !== "string") throw new Error(`${at}: "${key}" must map to a string`);
15531
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
+ }
15532
15567
  /** Deterministic order for `recorded` entries: lexicographic by (logicalId, path).
15533
15568
  * The single point where order is imposed — read/compare logic is order-independent,
15534
15569
  * so this only affects the bytes on disk. Without it the entries inherit findings
@@ -15565,7 +15600,8 @@ async function writeBaselineFile(b) {
15565
15600
  recorded: sortRecorded(b.recorded),
15566
15601
  ...b.completeResources ? { completeResources: [...b.completeResources].sort() } : {},
15567
15602
  ...b.recordedPhysicalIds ? { recordedPhysicalIds: sortedPhysicalIds(b.recordedPhysicalIds, b.recorded, b.completeResources ?? []) } : {},
15568
- ...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)) } : {}
15569
15605
  };
15570
15606
  await writeFile(p, JSON.stringify(stable, null, 2) + "\n", "utf8");
15571
15607
  return p;
@@ -15636,12 +15672,47 @@ async function writeBaseline(stackName, region, accountId, findings, rawTemplate
15636
15672
  recorded,
15637
15673
  completeResources,
15638
15674
  ...buildRecordedPhysicalIds(recorded, completeResources, opts.physicalIdByLogical, opts.previous),
15639
- ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous)
15675
+ ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous),
15676
+ ...buildObservedDefaults(findings, opts.previous)
15640
15677
  }),
15641
15678
  count: recorded.length
15642
15679
  };
15643
15680
  }
15644
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
+ /**
15645
15716
  * #674/#792: build the `recordedPhysicalIds` map (logicalId -> physical id) for the
15646
15717
  * resources being written. Covers every RECORDED logicalId PLUS every snapshot-`complete`
15647
15718
  * resource — the latter so a resource recorded as complete but with ZERO undeclared
@@ -16259,6 +16330,31 @@ function applyBaseline(findings, baseline, opts = {}) {
16259
16330
  note: "baseline value removed since record"
16260
16331
  });
16261
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
+ }
16262
16358
  if (promotedStale.length > 0) opts.warn?.(formatPromotedStaleNote(promotedStale));
16263
16359
  if (removedFromTemplate.length > 0) opts.warn?.(formatRemovedFromTemplateNote(removedFromTemplate));
16264
16360
  if (replacedStale.length > 0) opts.warn?.(formatReplacedStaleNote(replacedStale));