cdk-real-drift 0.25.3 → 0.25.4

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/README.md CHANGED
@@ -694,7 +694,8 @@ The table of every drift kind and its section label is up in
694
694
  in full as _potential_ (unconfirmed) drift and don't drive the `--fail` exit;
695
695
  `result:` points you at `cdkrd record` to accept them (or `revert` to remove).
696
696
  Once a resource is fully snapshotted, a value that _appears_ later is real drift
697
- (`appeared since record`).
697
+ (`appeared since record`) — and the same applies to a whole out-of-band-created
698
+ child resource once its parent's child inventory is recorded.
698
699
  - **`↳` origin hint**: when a finding's live value has a recognizable external
699
700
  source — e.g. the CloudWatch Application Signals / Lambda Insights
700
701
  auto-instrumentation footprint (an added Insights layer + tracer execution
package/dist/cli.js CHANGED
@@ -15253,6 +15253,8 @@ function addedFinding(parent, c, read) {
15253
15253
  physicalId: c.identifier,
15254
15254
  constructPath: `${parent.constructPath ?? parent.logicalId} ▸ ${c.label}`,
15255
15255
  resourceType: c.resourceType,
15256
+ parentLogicalId: parent.logicalId,
15257
+ parentResourceType: parent.resourceType,
15256
15258
  path: "",
15257
15259
  actual: read.model,
15258
15260
  note: read.ok ? "created out of band — not in your CloudFormation template" : "created out of band — not in your CloudFormation template; live model unreadable this run",
@@ -16084,6 +16086,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16084
16086
  const oaiCanonicalIds = buildOaiCanonicalIds(desired);
16085
16087
  const siblingStackCache = /* @__PURE__ */ new Map();
16086
16088
  const crossRegionProbe = makeCrossRegionSiblingProbe(desired.accountId, region);
16089
+ const childScanComplete = [];
16087
16090
  for (const r of desired.resources) {
16088
16091
  const enumerate = CHILD_ENUMERATORS[r.resourceType];
16089
16092
  if (!enumerate || !r.physicalId) continue;
@@ -16111,6 +16114,10 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16111
16114
  const read = await readAddedModel(cc, cfn, c, schemas, oaiCanonicalIds, region, desired.accountId);
16112
16115
  findings.push(addedFinding(r, c, read));
16113
16116
  }
16117
+ childScanComplete.push({
16118
+ logicalId: r.logicalId,
16119
+ resourceType: r.resourceType
16120
+ });
16114
16121
  } catch (e) {
16115
16122
  findings.push({
16116
16123
  tier: "skipped",
@@ -16121,6 +16128,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
16121
16128
  });
16122
16129
  }
16123
16130
  }
16131
+ desired.childScanComplete = childScanComplete;
16124
16132
  let kmsAliasTargets = {};
16125
16133
  if (desired.resources.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType))) {
16126
16134
  const resolved = await fetchManagedAliasTargets(region);
@@ -16472,7 +16480,8 @@ const KNOWN_BASELINE_KEYS = new Set([
16472
16480
  "completeResources",
16473
16481
  "recordedPhysicalIds",
16474
16482
  "recordedSourceFingerprints",
16475
- "observedDefaults"
16483
+ "observedDefaults",
16484
+ "enumeratedParents"
16476
16485
  ]);
16477
16486
  const KNOWN_RECORDED_ENTRY_KEYS = new Set([
16478
16487
  "logicalId",
@@ -16534,6 +16543,7 @@ async function loadBaseline(stackName, accountId, region) {
16534
16543
  validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
16535
16544
  validateRecordedSourceFingerprints(parsed.recordedSourceFingerprints, path);
16536
16545
  validateObservedDefaults(parsed.observedDefaults, path);
16546
+ validateEnumeratedParents(parsed.enumeratedParents, path);
16537
16547
  return parsed;
16538
16548
  }
16539
16549
  /**
@@ -16647,6 +16657,24 @@ function validateObservedDefaults(value, path) {
16647
16657
  if (unknown.length > 0) throw new Error(`${at}[${i}]: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "logicalId", "resourceType", "path"`);
16648
16658
  });
16649
16659
  }
16660
+ /**
16661
+ * #1737: validate `enumeratedParents` (optional). When present it must be an array of
16662
+ * { logicalId, resourceType } string pairs with no unknown keys — same loud-vs-silent
16663
+ * principle as validateObservedDefaults (a malformed marker would silently disable the
16664
+ * appeared-since-record confirmation this field exists to drive).
16665
+ */
16666
+ function validateEnumeratedParents(value, path) {
16667
+ if (value === void 0) return;
16668
+ const at = `baseline file ${path}: \`enumeratedParents\``;
16669
+ if (!Array.isArray(value)) throw new Error(`${at} must be an array of { logicalId, resourceType }`);
16670
+ value.forEach((entry, i) => {
16671
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new Error(`${at}[${i}] must be an object { logicalId, resourceType }`);
16672
+ const obj = entry;
16673
+ for (const k of ["logicalId", "resourceType"]) if (typeof obj[k] !== "string") throw new Error(`${at}[${i}]: "${k}" is required and must be a string`);
16674
+ const unknown = Object.keys(obj).filter((k) => k !== "logicalId" && k !== "resourceType");
16675
+ if (unknown.length > 0) throw new Error(`${at}[${i}]: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "logicalId", "resourceType"`);
16676
+ });
16677
+ }
16650
16678
  /** Deterministic order for `recorded` entries: lexicographic by (logicalId, path).
16651
16679
  * The single point where order is imposed — read/compare logic is order-independent,
16652
16680
  * so this only affects the bytes on disk. Without it the entries inherit findings
@@ -16684,7 +16712,8 @@ async function writeBaselineFile(b) {
16684
16712
  ...b.completeResources ? { completeResources: [...b.completeResources].sort() } : {},
16685
16713
  ...b.recordedPhysicalIds ? { recordedPhysicalIds: sortedPhysicalIds(b.recordedPhysicalIds, b.recorded, b.completeResources ?? []) } : {},
16686
16714
  ...b.recordedSourceFingerprints ? { recordedSourceFingerprints: sortedSourceFingerprints(b.recordedSourceFingerprints, b.recorded) } : {},
16687
- ...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)) } : {}
16715
+ ...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)) } : {},
16716
+ ...b.enumeratedParents && b.enumeratedParents.length > 0 ? { enumeratedParents: [...b.enumeratedParents].sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.resourceType < c.resourceType ? -1 : a.resourceType > c.resourceType ? 1 : 0)) } : {}
16688
16717
  };
16689
16718
  await writeFile(p, JSON.stringify(stable, null, 2) + "\n", "utf8");
16690
16719
  return p;
@@ -16756,12 +16785,37 @@ async function writeBaseline(stackName, region, accountId, findings, rawTemplate
16756
16785
  completeResources,
16757
16786
  ...buildRecordedPhysicalIds(recorded, completeResources, opts.physicalIdByLogical, opts.previous),
16758
16787
  ...buildRecordedSourceFingerprints(recorded, opts.declaredByLogical, opts.previous),
16759
- ...buildObservedDefaults(findings, opts.previous)
16788
+ ...buildObservedDefaults(findings, opts.previous),
16789
+ ...buildEnumeratedParents(opts.enumeratedParents, findings, recorded)
16760
16790
  }),
16761
16791
  count: recorded.length
16762
16792
  };
16763
16793
  }
16764
16794
  /**
16795
+ * #1737: finalize the `enumeratedParents` marker for this record run. Seeds from the
16796
+ * gather's scan-complete parents, then DEMOTES any parent that has an `added` finding
16797
+ * this run whose entry is NOT in the final recorded set — the user (selective picker /
16798
+ * drop flow) or the run itself (a model-read-failed child buildRecorded skips) declined
16799
+ * to endorse a PRESENT child, so marking the parent complete would let that child later
16800
+ * false-confirm as "appeared since record" (the #790 completeness-demotion mirror).
16801
+ * Deterministic sort; `{}` (spread to nothing) when empty so old-shaped baselines stay
16802
+ * byte-identical. Pure + exported for unit tests.
16803
+ */
16804
+ function buildEnumeratedParents(candidates, findings, recorded) {
16805
+ if (!candidates || candidates.length === 0) return {};
16806
+ const recordedKeys = new Set(recorded.map(recordedKey));
16807
+ const blocked = /* @__PURE__ */ new Set();
16808
+ for (const f of findings) {
16809
+ if (f.tier !== "added" || f.parentLogicalId === void 0) continue;
16810
+ if (!recordedKeys.has(recordedKey({
16811
+ logicalId: f.logicalId,
16812
+ path: f.path
16813
+ }))) blocked.add(`${f.parentLogicalId}\0${f.parentResourceType}`);
16814
+ }
16815
+ const out = candidates.filter((p) => !blocked.has(`${p.logicalId}\0${p.resourceType}`)).sort((a, c) => (a.logicalId < c.logicalId ? -1 : a.logicalId > c.logicalId ? 1 : 0) || (a.resourceType < c.resourceType ? -1 : a.resourceType > c.resourceType ? 1 : 0));
16816
+ return out.length > 0 ? { enumeratedParents: out } : {};
16817
+ }
16818
+ /**
16765
16819
  * #1637: build the `observedDefaults` entries for this record run. Seeds from THIS run's
16766
16820
  * `atDefault` findings on the curated OBSERVED_DEFAULT_TRACKED_PATHS, then carries forward
16767
16821
  * the previous baseline's entries for resources this run could NOT observe (a `skipped`
@@ -17253,6 +17307,7 @@ function applyBaseline(findings, baseline, opts = {}) {
17253
17307
  } : f);
17254
17308
  const recorded = baseline.recorded;
17255
17309
  const complete = new Set(baseline.completeResources ?? []);
17310
+ const enumeratedParents = baseline.enumeratedParents ?? [];
17256
17311
  const kept = [];
17257
17312
  const currentLogicalIds = opts.allLogicalIds === void 0 ? void 0 : Array.isArray(opts.allLogicalIds) ? new Set(opts.allLogicalIds) : opts.allLogicalIds;
17258
17313
  const recordedPhysIds = baseline.recordedPhysicalIds ?? {};
@@ -17296,6 +17351,13 @@ function applyBaseline(findings, baseline, opts = {}) {
17296
17351
  });
17297
17352
  continue;
17298
17353
  }
17354
+ if (f.parentLogicalId !== void 0 && enumeratedParents.some((ep) => ep.logicalId === f.parentLogicalId && ep.resourceType === f.parentResourceType)) {
17355
+ kept.push({
17356
+ ...f,
17357
+ note: f.note ? `${f.note}; appeared since record` : "appeared since record"
17358
+ });
17359
+ continue;
17360
+ }
17299
17361
  kept.push({
17300
17362
  ...f,
17301
17363
  unrecorded: true
@@ -20318,6 +20380,8 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
20318
20380
  "AWS::EC2::CapacityReservation\0InstanceMatchCriteria",
20319
20381
  "AWS::EC2::CapacityReservation\0EndDateType",
20320
20382
  "AWS::CodeDeploy::DeploymentGroup\0DeploymentConfigName",
20383
+ "AWS::CodeDeploy::DeploymentGroup\0DeploymentStyle",
20384
+ "AWS::CodeDeploy::DeploymentGroup\0LoadBalancerInfo",
20321
20385
  "AWS::DLM::LifecyclePolicy\0RetainInterval",
20322
20386
  "AWS::DLM::LifecyclePolicy\0CreateInterval",
20323
20387
  "AWS::IAM::Role\0MaxSessionDuration",
@@ -20424,7 +20488,8 @@ const REVERT_SET_DEFAULT_VALUES = {
20424
20488
  "AWS::DocDB::DBCluster\0DeletionProtection": false,
20425
20489
  "AWS::EKS::Cluster\0ResourcesVpcConfig.EndpointPrivateAccess": false,
20426
20490
  "AWS::ApiGatewayV2::IntegrationResponse\0TemplateSelectionExpression": "",
20427
- "AWS::ApiGatewayV2::RouteResponse\0ModelSelectionExpression": ""
20491
+ "AWS::ApiGatewayV2::RouteResponse\0ModelSelectionExpression": "",
20492
+ "AWS::CodeDeploy::DeploymentGroup\0LoadBalancerInfo": { TargetGroupInfoList: [] }
20428
20493
  };
20429
20494
  /**
20430
20495
  * A nested undeclared value (a live sub-key inside a declared object, R96/R98) — a dotted
@@ -21711,6 +21776,7 @@ async function recordStack(p) {
21711
21776
  allLogicalIds: desired.resources.map((r) => r.logicalId),
21712
21777
  previous: existing,
21713
21778
  physicalIdByLogical: physicalIdsByLogical(desired.resources),
21779
+ enumeratedParents: desired.childScanComplete,
21714
21780
  declaredByLogical: declaredKeysByLogical(desired.resources)
21715
21781
  });
21716
21782
  if (!p.json) console.log(style.ok(recordOutcomeMessage(stackName, path, count, refreshedOnly, !!existing)));