cdk-real-drift 0.9.3 → 0.9.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
@@ -404,7 +404,10 @@ error (they select which comparison runs, so a combination is contradictory).
404
404
  ### Interactive prompts (TTY only, CI is never prompted)
405
405
 
406
406
  Every option runs exactly the same code as the standalone commands. Prompts are
407
- skipped under `--json`, `--show-all`, `--pre-deploy`, and `--fail`. A non-TTY run
407
+ skipped under `--json`, `--show-all`, `--pre-deploy`, `--fail`, and the scope
408
+ filters `--declared-only` / `--undeclared-only` (a filtered finding set must never
409
+ become a snapshot-complete baseline via the inline Record — use the standalone
410
+ `record` verb, which sees the unfiltered state, #779). A non-TTY run
408
411
  never prompts: a required write decision without `--yes` errors with exit 2 (the
409
412
  safe side). "Interactive" requires **both** a TTY stdin and a TTY stdout — so
410
413
  **redirecting or piping the output** (`cdkrd check > report.txt`, `| tee`) is also
package/dist/cli.js CHANGED
@@ -2208,7 +2208,10 @@ const KNOWN_DEFAULTS = {
2208
2208
  Domain: "vpc"
2209
2209
  },
2210
2210
  "AWS::EC2::TransitGateway": { SecurityGroupReferencingSupport: "disable" },
2211
- "AWS::EC2::FlowLog": { MaxAggregationInterval: 600 },
2211
+ "AWS::EC2::FlowLog": {
2212
+ MaxAggregationInterval: 600,
2213
+ LogFormat: "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}"
2214
+ },
2212
2215
  "AWS::EC2::PlacementGroup": { SpreadLevel: "rack" },
2213
2216
  "AWS::EC2::IPAM": { MeteredAccount: "ipam-owner" },
2214
2217
  "AWS::EC2::ClientVpnEndpoint": {
@@ -2811,7 +2814,9 @@ const GENERATED_LOGICALID_PREFIX_PATHS = {
2811
2814
  "AWS::Cognito::IdentityPool": new Set(["IdentityPoolName"]),
2812
2815
  "AWS::Cognito::UserPool": new Set(["UserPoolName"]),
2813
2816
  "AWS::Batch::JobDefinition": new Set(["JobDefinitionName"]),
2814
- "AWS::EC2::LaunchTemplate": new Set(["LaunchTemplateName"])
2817
+ "AWS::EC2::LaunchTemplate": new Set(["LaunchTemplateName"]),
2818
+ "AWS::WAFv2::WebACL": new Set(["Name"]),
2819
+ "AWS::WAFv2::RegexPatternSet": new Set(["Name"])
2815
2820
  };
2816
2821
  const CFN_LOGICALID_RANDOM = /[-_][0-9A-Za-z]{12,}$/;
2817
2822
  function isLogicalIdPrefixedGeneratedName(value, logicalId) {
@@ -2947,6 +2952,8 @@ function ebOptionSettingTier(namespace, optionName, value, envType) {
2947
2952
  }
2948
2953
  const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
2949
2954
  "AWS::ElasticLoadBalancingV2::LoadBalancer": new Set(["SecurityGroups"]),
2955
+ "AWS::ApiGateway::ApiKey": new Set(["Value"]),
2956
+ "AWS::Backup::BackupVault": new Set(["EncryptionKeyArn"]),
2950
2957
  "AWS::Batch::JobQueue": new Set(["JobQueueType"]),
2951
2958
  "AWS::ECS::Service": new Set(["AvailabilityZoneRebalancing", "PlatformVersion"]),
2952
2959
  "AWS::KinesisAnalyticsV2::Application": new Set(["ApplicationMaintenanceConfiguration"]),
@@ -3004,7 +3011,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3004
3011
  "ClusterVersion"
3005
3012
  ]),
3006
3013
  "AWS::OpenSearchService::Domain": new Set(["OffPeakWindowOptions"]),
3007
- "AWS::AmazonMQ::Broker": new Set(["MaintenanceWindowStartTime"]),
3014
+ "AWS::AmazonMQ::Broker": new Set([
3015
+ "MaintenanceWindowStartTime",
3016
+ "SecurityGroups",
3017
+ "SubnetIds"
3018
+ ]),
3008
3019
  "AWS::EC2::Instance": new Set(["PrivateIpAddress"]),
3009
3020
  "AWS::EC2::NetworkInterface": new Set([
3010
3021
  "PrivateIpAddress",
@@ -13599,6 +13610,9 @@ function isManagedPolicyAttachmentMember(f) {
13599
13610
  function isNestedSdkWritable(f) {
13600
13611
  return SDK_NESTED_WRITERS[f.resourceType]?.match(f.path) ?? false;
13601
13612
  }
13613
+ function isContractOp(op) {
13614
+ return op.contract === true;
13615
+ }
13602
13616
  function nullHuskRemovalOps(model) {
13603
13617
  const ops = [];
13604
13618
  const walk = (value, pointer) => {
@@ -13607,6 +13621,7 @@ function nullHuskRemovalOps(model) {
13607
13621
  if (pointer !== "") ops.push({
13608
13622
  op: "remove",
13609
13623
  path: pointer,
13624
+ contract: true,
13610
13625
  human: `strip null array husk at ${pointer}`
13611
13626
  });
13612
13627
  return;
@@ -14472,6 +14487,7 @@ function recordOutcomeMessage(stackName, path, count, refreshedOnly, hadPriorBas
14472
14487
  function revertSelectOptions(plan) {
14473
14488
  const options = [];
14474
14489
  for (const item of plan.items) for (const op of item.ops) {
14490
+ if (isContractOp(op)) continue;
14475
14491
  const marker = item.kind === "delete" ? " (DELETE)" : op.op === "remove" ? " (REMOVE)" : "";
14476
14492
  options.push({
14477
14493
  value: revertOpKey(item, op),
@@ -14485,13 +14501,31 @@ function revertOpKey(item, op) {
14485
14501
  const attr = op.attributeKey !== void 0 ? `${op.attributeKey}` : "";
14486
14502
  return `${item.logicalId}${item.kind}${op.path}${attr}`;
14487
14503
  }
14488
- /** Keep only the selected ops; items left with no ops drop out. Pure + exported. */
14504
+ /**
14505
+ * Keep only the selected ops; items left with no REAL op drop out. Pure + exported.
14506
+ *
14507
+ * #967: a CONTRACT op (null-husk strip) is never a selectable row, so it is never in
14508
+ * `picked` — but it is coupled to its item's real revert ops (without the strip, the CC
14509
+ * patch hard-fails model validation, #641). So it is NOT filtered by the pick set: it
14510
+ * ALWAYS rides along an item that retains ≥1 real (non-contract) selected op, and is
14511
+ * DROPPED with the whole item when the user selected none of that item's real ops.
14512
+ * This keeps both invariants: a real revert op can never be sent without its coupled
14513
+ * husk strip, and a husk strip can never be sent alone as a user-chosen write.
14514
+ */
14489
14515
  function filterRevertPlan(plan, picked) {
14490
14516
  return {
14491
- items: plan.items.map((item) => ({
14492
- ...item,
14493
- ops: item.ops.filter((op) => picked.has(revertOpKey(item, op)))
14494
- })).filter((item) => item.ops.length > 0),
14517
+ items: plan.items.map((item) => {
14518
+ const realSelected = item.ops.filter((op) => !isContractOp(op) && picked.has(revertOpKey(item, op)));
14519
+ if (realSelected.length === 0) return {
14520
+ ...item,
14521
+ ops: []
14522
+ };
14523
+ const contract = item.ops.filter(isContractOp);
14524
+ return {
14525
+ ...item,
14526
+ ops: [...contract, ...realSelected]
14527
+ };
14528
+ }).filter((item) => item.ops.length > 0),
14495
14529
  notRevertable: plan.notRevertable
14496
14530
  };
14497
14531
  }
@@ -14499,6 +14533,16 @@ function revertSelectMessage(stackName, region) {
14499
14533
  return `${stackLabel$1(stackName, region)}: select the op(s) to revert (unselected are not written)`;
14500
14534
  }
14501
14535
  /**
14536
+ * #967: the op count SHOWN to the user (confirm prompt + --dry-run preview) counts only
14537
+ * REAL revert ops — a CONTRACT op (null-husk strip) is plumbing coupled to a real op,
14538
+ * not a distinct write the user chose, so counting it would inflate the number the user
14539
+ * consents to. The full augmented patch (contract ops included) is still what is SENT to
14540
+ * AWS; this is purely the user-facing intent count. Pure + exported for unit tests.
14541
+ */
14542
+ function realOpCount(plan) {
14543
+ return plan.items.reduce((n, i) => n + i.ops.filter((op) => !isContractOp(op)).length, 0);
14544
+ }
14545
+ /**
14502
14546
  * Record the current undeclared state into the baseline file. In an interactive run
14503
14547
  * (no --yes) the user picks WHICH undeclared values to record (selective record, R14).
14504
14548
  * When an existing baseline is present the multiselect shows only the DELTA from it
@@ -14728,7 +14772,7 @@ function formatPlan(stackName, region, plan, opts = {}) {
14728
14772
  const planByResource = /* @__PURE__ */ new Map();
14729
14773
  for (const item of plan.items) {
14730
14774
  const g = planByResource.get(item.logicalId);
14731
- const humans = item.ops.map((op) => op.human);
14775
+ const humans = item.ops.filter((op) => !isContractOp(op)).map((op) => op.human);
14732
14776
  if (g) g.humans.push(...humans);
14733
14777
  else planByResource.set(item.logicalId, {
14734
14778
  displayId: item.displayId,
@@ -14881,7 +14925,7 @@ async function revertStack(p) {
14881
14925
  }
14882
14926
  if (dryRun) {
14883
14927
  const augmented = augment(plan);
14884
- const opCount = augmented.items.reduce((n, i) => n + i.ops.length, 0);
14928
+ const opCount = realOpCount(augmented);
14885
14929
  out(`\n(dry-run) would apply ${opCount} op(s) to ${augmented.items.length} resource(s). No changes made.`);
14886
14930
  return {
14887
14931
  exit: 0,
@@ -14919,7 +14963,7 @@ async function revertStack(p) {
14919
14963
  }
14920
14964
  }
14921
14965
  const confirmPlan = augment(plan);
14922
- const opCount = confirmPlan.items.reduce((n, i) => n + i.ops.length, 0);
14966
+ const opCount = realOpCount(confirmPlan);
14923
14967
  const deleteCount = confirmPlan.items.filter((i) => i.kind === "delete").length;
14924
14968
  const ok = await confirm({
14925
14969
  message: revertConfirmMessage(stackName, region, opCount, plan.notRevertable.length, deleteCount),
@@ -16255,6 +16299,19 @@ function finalCheckExit(code, fail) {
16255
16299
  * who can make the decision. It is gated OUT of every machine/automation mode:
16256
16300
  * - --json / --show-all / --pre-deploy — machine output or baseline-untouched contracts,
16257
16301
  * - --fail — the CI drift-exit path,
16302
+ * - #779: --declared-only / --undeclared-only — a SCOPE filter is active, so `findings`
16303
+ * has been reduced to one tier (declared-only drops the whole undeclared/added/atDefault
16304
+ * tier; undeclared-only drops declared plus its readGap/unresolved byproducts). The
16305
+ * interactive menu's Record path feeds THAT filtered set into writeBaseline, and
16306
+ * computeCompleteResources — which only blocks snapshot-completeness on the tiers that
16307
+ * were just filtered out (skipped/deleted/readGap/unrecorded-undeclared) — then stamps
16308
+ * every readable resource snapshot-complete with an INCOMPLETE `recorded` list. A later
16309
+ * plain `check` reads the genuinely-undeclared values on those "complete" resources as
16310
+ * "appeared since record" -> a false confirmed-drift storm (exit 1 under --fail). Under
16311
+ * --declared-only the HELP/in-run note also PROMISES the baseline is untouched, which the
16312
+ * Record offer would violate. A filtered finding set must never become a snapshot-complete
16313
+ * baseline, so no interactive Record/Revert is offered under either scope flag; the
16314
+ * standalone `record` verb (unfiltered) remains the way to establish one.
16258
16315
  * - #1054: --yes — `--yes` has NO documented `check` contract (HELP scopes it to record /
16259
16316
  * ignore / revert; check's automation flag is --fail / non-TTY). In the menu the USER is
16260
16317
  * the decision-maker, but `--yes` means "no decision needed" in the record/ignore/revert
@@ -16264,7 +16321,7 @@ function finalCheckExit(code, fail) {
16264
16321
  * Pure + exported for tests.
16265
16322
  */
16266
16323
  function shouldOfferInteractiveResolve(a, ctx) {
16267
- return (ctx.code === 1 || ctx.hasUnrecorded || !ctx.hasBaseline) && !a.json && !a.showAll && !a.preDeploy && !a.fail && !a.yes && ctx.interactive;
16324
+ return (ctx.code === 1 || ctx.hasUnrecorded || !ctx.hasBaseline) && !a.json && !a.showAll && !a.preDeploy && !a.fail && !a.yes && !a.declaredOnly && !a.undeclaredOnly && ctx.interactive;
16268
16325
  }
16269
16326
  /**
16270
16327
  * #781: does a committed baseline exist for this stack IN THE REGION being checked?