cdk-real-drift 0.7.4 → 0.7.6

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
@@ -1051,6 +1051,10 @@ function buildStackSelector(patterns) {
1051
1051
  };
1052
1052
  }
1053
1053
  const CONCRETE_REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
1054
+ const CONCRETE_ACCOUNT = /^\d{12}$/;
1055
+ function concreteAccount(raw) {
1056
+ return raw && CONCRETE_ACCOUNT.test(raw) ? raw : void 0;
1057
+ }
1054
1058
  /**
1055
1059
  * Build the stderr message body (no `warning:` prefix — the caller adds it) for the case where
1056
1060
  * `--app` points at a pre-synthesized cloud-assembly DIRECTORY (`cdk.out`) yet the user also
@@ -1145,17 +1149,23 @@ async function synthApp(app, opts = {}) {
1145
1149
  return cached.cloudAssembly.stacksRecursively.map((s) => ({
1146
1150
  stackName: s.stackName,
1147
1151
  region: CONCRETE_REGION.test(s.environment.region) ? s.environment.region : void 0,
1152
+ account: concreteAccount(s.environment.account),
1148
1153
  template: s.template
1149
1154
  }));
1150
1155
  } finally {
1151
1156
  await cached.dispose();
1152
1157
  }
1153
1158
  }
1154
- /** Synth and return each stack's name + its own (concrete) region + template, for discovery. */
1159
+ /**
1160
+ * Synth and return each stack's name + its own (concrete) region + account + template, for
1161
+ * discovery. The account (#740) lets check distinguish a stack pinned to another account from
1162
+ * a never-deployed one.
1163
+ */
1155
1164
  async function discoverStacks(app, opts = {}) {
1156
1165
  return (await synthApp(app, opts)).map((s) => ({
1157
1166
  stackName: s.stackName,
1158
1167
  region: s.region,
1168
+ account: s.account,
1159
1169
  template: s.template
1160
1170
  }));
1161
1171
  }
@@ -1240,17 +1250,19 @@ async function resolveStacks(a) {
1240
1250
  if (a.all || a.stackNames.length === 0) return discovered.map((s) => ({
1241
1251
  stackName: s.stackName,
1242
1252
  region: s.region ?? fallbackRegion,
1253
+ account: s.account,
1243
1254
  template: s.template
1244
1255
  }));
1245
1256
  const seen = /* @__PURE__ */ new Set();
1246
1257
  const out = [];
1247
- const add = (stackName, region, template) => {
1258
+ const add = (stackName, region, account, template) => {
1248
1259
  const key = `${stackName}\0${region ?? ""}`;
1249
1260
  if (seen.has(key)) return;
1250
1261
  seen.add(key);
1251
1262
  out.push({
1252
1263
  stackName,
1253
1264
  region,
1265
+ account,
1254
1266
  template
1255
1267
  });
1256
1268
  };
@@ -1259,13 +1271,13 @@ async function resolveStacks(a) {
1259
1271
  let matched = 0;
1260
1272
  for (const s of discovered) if (matchesGlob(name, s.stackName)) {
1261
1273
  matched++;
1262
- add(s.stackName, s.region ?? fallbackRegion, s.template);
1274
+ add(s.stackName, s.region ?? fallbackRegion, s.account, s.template);
1263
1275
  }
1264
1276
  if (matched === 0) throw new Error(`glob "${name}" matched no stacks defined by the CDK app (found: ${known()})`);
1265
1277
  } else {
1266
1278
  const hits = discovered.filter((s) => s.stackName === name);
1267
1279
  if (hits.length === 0) throw new Error(`stack "${name}" is not defined by the CDK app (found: ${known()})`);
1268
- for (const hit of hits) add(hit.stackName, hit.region ?? fallbackRegion, hit.template);
1280
+ for (const hit of hits) add(hit.stackName, hit.region ?? fallbackRegion, hit.account, hit.template);
1269
1281
  }
1270
1282
  if (out.length === 0) throw new Error(`no stacks match ${a.stackNames.join(", ")} (found: ${known()})`);
1271
1283
  return out;
@@ -4842,6 +4854,27 @@ const CLUSTER_ECHO_CHILD = {
4842
4854
  };
4843
4855
  const isKeyValueEntry = (t) => !!t && typeof t === "object" && typeof t.Key === "string" && "Value" in t;
4844
4856
  const REFLECTED_CHILD_PROPS = { "AWS::SNS::Topic": "Subscription" };
4857
+ const EVENT_BUS_TYPE = "AWS::Events::EventBus";
4858
+ const EVENT_BUS_POLICY_PROP = "Policy";
4859
+ function subtractSiblingEventBusStatements(live, siblingStatements) {
4860
+ const policy = live[EVENT_BUS_POLICY_PROP];
4861
+ if (!policy || typeof policy !== "object") return;
4862
+ const arr = policy.Statement;
4863
+ if (!Array.isArray(arr) || siblingStatements.length === 0) return;
4864
+ for (const sib of siblingStatements) {
4865
+ if (!sib || typeof sib !== "object") continue;
4866
+ const sub = sib;
4867
+ const sibSid = sub.Sid;
4868
+ const i = arr.findIndex((el) => {
4869
+ if (el === null || typeof el !== "object") return false;
4870
+ const e = el;
4871
+ if (typeof sibSid === "string" && sibSid) return e.Sid === sibSid;
4872
+ return Object.entries(sub).every(([k, v]) => v === UNRESOLVED || deepEqual(e[k], v));
4873
+ });
4874
+ if (i >= 0) arr.splice(i, 1);
4875
+ }
4876
+ if (arr.length === 0) delete live[EVENT_BUS_POLICY_PROP];
4877
+ }
4845
4878
  const IAM_PRINCIPAL_POLICY_TYPES = new Set([
4846
4879
  "AWS::IAM::Role",
4847
4880
  "AWS::IAM::User",
@@ -4866,6 +4899,37 @@ function subtractSiblingSgRules(live, prop, siblingRules) {
4866
4899
  }
4867
4900
  if (arr.length === 0) delete live[prop];
4868
4901
  }
4902
+ const IAM_ATTACHMENT_REFLECTION_TYPES = new Set([
4903
+ "AWS::IAM::Role",
4904
+ "AWS::IAM::User",
4905
+ "AWS::IAM::Group"
4906
+ ]);
4907
+ const MANAGED_POLICY_ARNS_PROP = "ManagedPolicyArns";
4908
+ function managedPolicyRefMatches(liveVal, sibVal) {
4909
+ if (typeof liveVal !== "string" || typeof sibVal !== "string") return false;
4910
+ if (liveVal === sibVal) return true;
4911
+ const tail = (s) => s.startsWith("arn:") ? s.split("/").pop() ?? s : s;
4912
+ return tail(liveVal) === tail(sibVal);
4913
+ }
4914
+ function subtractSiblingManagedPolicyArns(live, siblingArns) {
4915
+ const arr = live[MANAGED_POLICY_ARNS_PROP];
4916
+ if (!Array.isArray(arr) || siblingArns.length === 0) return;
4917
+ for (const sib of siblingArns) {
4918
+ const i = arr.findIndex((el) => managedPolicyRefMatches(el, sib));
4919
+ if (i >= 0) arr.splice(i, 1);
4920
+ }
4921
+ if (arr.length === 0) delete live[MANAGED_POLICY_ARNS_PROP];
4922
+ }
4923
+ const USER_GROUPS_PROP = "Groups";
4924
+ function subtractSiblingUserGroups(live, siblingGroups) {
4925
+ const arr = live[USER_GROUPS_PROP];
4926
+ if (!Array.isArray(arr) || siblingGroups.length === 0) return;
4927
+ for (const sib of siblingGroups) {
4928
+ const i = arr.findIndex((el) => el === sib);
4929
+ if (i >= 0) arr.splice(i, 1);
4930
+ }
4931
+ if (arr.length === 0) delete live[USER_GROUPS_PROP];
4932
+ }
4869
4933
  const CC_ALT_REPRESENTATION = {
4870
4934
  "AWS::EC2::Subnet": {
4871
4935
  AvailabilityZoneId: "AvailabilityZone",
@@ -5232,6 +5296,11 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5232
5296
  const declared = canonicalizeForCompare(rewriteOaiPrincipalsDeep(declaredForCompare, oaiMap), resourceType);
5233
5297
  const reflected = REFLECTED_CHILD_PROPS[resourceType];
5234
5298
  if (reflected && !(reflected in declared)) delete live[reflected];
5299
+ if (resourceType === EVENT_BUS_TYPE && !(EVENT_BUS_POLICY_PROP in declared)) {
5300
+ const busKey = physicalId ?? resource.declared.Name;
5301
+ const sibStatements = typeof busKey === "string" ? opts.siblingEventBusPolicies?.[busKey] : void 0;
5302
+ if (sibStatements) subtractSiblingEventBusStatements(live, sibStatements);
5303
+ }
5235
5304
  if (resourceType === "AWS::ECS::Cluster" && resource.hasSiblingCapacityProviders) {
5236
5305
  for (const p of ["CapacityProviders", "DefaultCapacityProviderStrategy"]) if (!(p in declared)) delete live[p];
5237
5306
  }
@@ -5243,6 +5312,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5243
5312
  const sib = physicalId ? opts.siblingSgRules?.[physicalId] : void 0;
5244
5313
  if (sib) for (const [prop, side] of Object.entries(SG_RULE_REFLECTION)) subtractSiblingSgRules(live, prop, sib[side]);
5245
5314
  }
5315
+ if (IAM_ATTACHMENT_REFLECTION_TYPES.has(resourceType)) {
5316
+ const sibArns = physicalId ? opts.siblingManagedPolicyAttachments?.[physicalId] : void 0;
5317
+ if (sibArns) subtractSiblingManagedPolicyArns(live, sibArns);
5318
+ if (resourceType === "AWS::IAM::User") {
5319
+ const sibGroups = physicalId ? opts.siblingUserGroups?.[physicalId] : void 0;
5320
+ if (sibGroups) subtractSiblingUserGroups(live, sibGroups);
5321
+ }
5322
+ }
5246
5323
  if (resourceType === "AWS::S3::Bucket" && physicalId && opts.bucketNotificationManaged?.has(physicalId) && !("NotificationConfiguration" in declared)) delete live.NotificationConfiguration;
5247
5324
  const echoSpec = CLUSTER_ECHO_CHILD[resourceType];
5248
5325
  const echoModel = echoSpec && physicalId ? opts.clusterEchoModel?.[physicalId] : void 0;
@@ -10221,6 +10298,28 @@ function buildSiblingSgRules(desired) {
10221
10298
  }
10222
10299
  return map;
10223
10300
  }
10301
+ const EVENT_BUS_POLICY_TYPE = "AWS::Events::EventBusPolicy";
10302
+ const DEFAULT_EVENT_BUS = "default";
10303
+ function buildSiblingEventBusPolicies(desired) {
10304
+ const map = {};
10305
+ for (const r of desired.resources) {
10306
+ if (r.resourceType !== EVENT_BUS_POLICY_TYPE) continue;
10307
+ const decl = r.declared;
10308
+ if (!decl || typeof decl !== "object") continue;
10309
+ const d = decl;
10310
+ const busName = d.EventBusName;
10311
+ let busKey;
10312
+ if (busName === void 0) busKey = DEFAULT_EVENT_BUS;
10313
+ else if (typeof busName === "string" && busName) busKey = busName;
10314
+ else continue;
10315
+ const stmt = d.Statement;
10316
+ if (!stmt || typeof stmt !== "object") continue;
10317
+ const statement = { ...stmt };
10318
+ if (statement.Sid === void 0 && typeof d.StatementId === "string" && d.StatementId) statement.Sid = d.StatementId;
10319
+ (map[busKey] ??= []).push(statement);
10320
+ }
10321
+ return map;
10322
+ }
10224
10323
  const S3_NOTIFICATIONS_CR_TYPE = "Custom::S3BucketNotifications";
10225
10324
  function buildBucketNotificationManaged(desired) {
10226
10325
  const byLogicalId = /* @__PURE__ */ new Map();
@@ -10239,6 +10338,62 @@ function buildBucketNotificationManaged(desired) {
10239
10338
  }
10240
10339
  return managed;
10241
10340
  }
10341
+ const MANAGED_POLICY_TYPE = "AWS::IAM::ManagedPolicy";
10342
+ const MANAGED_POLICY_ATTACH_SIDES = [
10343
+ "Roles",
10344
+ "Users",
10345
+ "Groups"
10346
+ ];
10347
+ function buildSiblingManagedPolicyAttachments(desired) {
10348
+ const byLogicalId = /* @__PURE__ */ new Map();
10349
+ for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
10350
+ const map = {};
10351
+ for (const r of desired.resources) {
10352
+ if (r.resourceType !== MANAGED_POLICY_TYPE) continue;
10353
+ const decl = r.declared;
10354
+ if (!decl || typeof decl !== "object") continue;
10355
+ const d = decl;
10356
+ const attached = r.physicalId ?? (typeof d.ManagedPolicyName === "string" && d.ManagedPolicyName ? d.ManagedPolicyName : void 0);
10357
+ if (!attached) continue;
10358
+ for (const side of MANAGED_POLICY_ATTACH_SIDES) {
10359
+ const list = d[side];
10360
+ if (!Array.isArray(list)) continue;
10361
+ for (const principal of list) {
10362
+ const key = resolvePrincipalKey(principal, byLogicalId);
10363
+ if (key) (map[key] ??= []).push(attached);
10364
+ }
10365
+ }
10366
+ }
10367
+ return map;
10368
+ }
10369
+ const USER_TO_GROUP_TYPE = "AWS::IAM::UserToGroupAddition";
10370
+ function buildSiblingUserGroups(desired) {
10371
+ const byLogicalId = /* @__PURE__ */ new Map();
10372
+ for (const r of desired.resources) if (r.physicalId) byLogicalId.set(r.logicalId, r.physicalId);
10373
+ const map = {};
10374
+ for (const r of desired.resources) {
10375
+ if (r.resourceType !== USER_TO_GROUP_TYPE) continue;
10376
+ const decl = r.declared;
10377
+ if (!decl || typeof decl !== "object") continue;
10378
+ const d = decl;
10379
+ const group = resolvePrincipalKey(d.GroupName, byLogicalId);
10380
+ if (!group) continue;
10381
+ const users = d.Users;
10382
+ if (!Array.isArray(users)) continue;
10383
+ for (const user of users) {
10384
+ const key = resolvePrincipalKey(user, byLogicalId);
10385
+ if (key) (map[key] ??= []).push(group);
10386
+ }
10387
+ }
10388
+ return map;
10389
+ }
10390
+ function resolvePrincipalKey(ref, byLogicalId) {
10391
+ if (typeof ref === "string" && ref) return ref;
10392
+ if (ref && typeof ref === "object" && "Ref" in ref) {
10393
+ const logicalId = ref.Ref;
10394
+ if (typeof logicalId === "string") return byLogicalId.get(logicalId);
10395
+ }
10396
+ }
10242
10397
  function buildClusterEchoModels(desired) {
10243
10398
  const parentTypes = new Set(Object.values(CLUSTER_ECHO_CHILD).map((s) => s.parentType));
10244
10399
  const clusterByPhys = {};
@@ -10391,6 +10546,9 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
10391
10546
  kmsAliasTargets,
10392
10547
  oaiCanonicalIds,
10393
10548
  siblingSgRules: buildSiblingSgRules(desired),
10549
+ siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
10550
+ siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10551
+ siblingUserGroups: buildSiblingUserGroups(desired),
10394
10552
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10395
10553
  clusterEchoModel: buildClusterEchoModels(desired)
10396
10554
  };
@@ -10449,6 +10607,9 @@ async function regatherTouched(gathered, touched, region) {
10449
10607
  kmsAliasTargets,
10450
10608
  oaiCanonicalIds,
10451
10609
  siblingSgRules: buildSiblingSgRules(desired),
10610
+ siblingEventBusPolicies: buildSiblingEventBusPolicies(desired),
10611
+ siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10612
+ siblingUserGroups: buildSiblingUserGroups(desired),
10452
10613
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10453
10614
  clusterEchoModel: buildClusterEchoModels(desired)
10454
10615
  };
@@ -13567,12 +13728,26 @@ function buildRevertPlan(findings, baseline, opts = {}) {
13567
13728
  notRevertable
13568
13729
  };
13569
13730
  }
13731
+ function coerceDeclaredScalar(desired, live) {
13732
+ if (typeof desired !== "string") return desired;
13733
+ if (typeof live === "number") {
13734
+ const n = Number(desired);
13735
+ if (Number.isFinite(n) && desired.trim() !== "") return n;
13736
+ return desired;
13737
+ }
13738
+ if (typeof live === "boolean") {
13739
+ if (desired === "true") return true;
13740
+ if (desired === "false") return false;
13741
+ return desired;
13742
+ }
13743
+ return desired;
13744
+ }
13570
13745
  function revertOp(f, recorded) {
13571
13746
  const pointer = toPointer(f.path);
13572
13747
  if (f.tier === "declared") return {
13573
13748
  op: "add",
13574
13749
  path: pointer,
13575
- value: f.desired,
13750
+ value: coerceDeclaredScalar(f.desired, f.actual),
13576
13751
  prior: f.actual,
13577
13752
  ...f.attributeKey !== void 0 && { attributeKey: f.attributeKey },
13578
13753
  human: `${f.path}${f.attributeKey ? `[${f.attributeKey}]` : ""} -> deployed-template value`
@@ -14697,21 +14872,24 @@ async function revertStack(p) {
14697
14872
  for (const item of plan.items) {
14698
14873
  if (item.kind === "delete" || !okIds.has(item.logicalId)) continue;
14699
14874
  for (const op of item.ops) {
14700
- if (op.op !== "remove") continue;
14875
+ if (op.op !== "remove" && op.op !== "add") continue;
14701
14876
  const dotted = op.path.replace(/^\//, "").replace(/\//g, ".");
14702
14877
  const key = `${item.logicalId}\0${dotted}`;
14703
14878
  if (!preActual.has(key)) continue;
14704
14879
  const pre = preActual.get(key);
14705
- if (post.some((f) => f.logicalId === item.logicalId && f.path === dotted && !isDrift(f) && deepEqual(f.actual, pre))) noOpRemovals.push({
14880
+ const post0 = post.find((f) => f.logicalId === item.logicalId && f.path === dotted && !isDrift(f));
14881
+ const persisted = post0 !== void 0 && deepEqual(post0.actual, pre);
14882
+ if (op.op === "remove" ? persisted : persisted && !deepEqual(post0.actual, op.value)) noOpRemovals.push({
14706
14883
  displayId: item.displayId,
14707
- path: dotted
14884
+ path: dotted,
14885
+ kind: op.op
14708
14886
  });
14709
14887
  }
14710
14888
  }
14711
14889
  const unverified = post.filter((f) => touched.has(f.logicalId) && f.tier === "skipped").length;
14712
14890
  const unconfirmed = unverified + failedDeleteIds.size + failedUpdateIds.size;
14713
14891
  const converged = remaining === 0 && unconfirmed === 0 && noOpRemovals.length === 0;
14714
- for (const n of noOpRemovals) out(style.fail(` NOT reverted: ${n.displayId}.${n.path} — removal was a no-op (the provider ignored the omitted property; it needs an explicit default write — see #597 / REVERT_SET_DEFAULT_PATHS)`));
14892
+ for (const n of noOpRemovals) out(style.fail(n.kind === "remove" ? ` NOT reverted: ${n.displayId}.${n.path} — removal was a no-op (the provider ignored the omitted property; it needs an explicit default write — see #597 / REVERT_SET_DEFAULT_PATHS)` : ` NOT reverted: ${n.displayId}.${n.path} — the default-value write was a no-op (the provider accepted but ignored it; the out-of-band value persists — see #763 / REVERT_SET_DEFAULT_PATHS)`));
14715
14893
  const notConverged = unconfirmed + noOpRemovals.length;
14716
14894
  out(converged ? style.clean(`${stackName}: CLEAN after revert.`) : remaining > 0 ? style.drift(`${stackName}: ${remaining} drift(s) remain.`) : style.drift(`${stackName}: revert applied, but ${notConverged} value(s) could not be confirmed converged (see above).`));
14717
14895
  const unrecordedLeft = unrecordedCount(post);
@@ -15972,6 +16150,36 @@ async function resolveCallerAccount(region) {
15972
16150
  return;
15973
16151
  }
15974
16152
  }
16153
+ /**
16154
+ * #740: decide whether a stack must be SKIPPED because it is pinned (via `env.account`) to a
16155
+ * different AWS account than the active credentials are for.
16156
+ *
16157
+ * A CDK app with dev+prod stacks in DIFFERENT accounts (the CDK Pipelines / multi-env staple)
16158
+ * is checked one account at a time — the caller runs `check --all` per account with that
16159
+ * account's credentials. A stack whose `env.account` names an OTHER account cannot be read
16160
+ * with the current creds: `DescribeStacks` throws "does not exist" (the stack IS deployed, just
16161
+ * in its own account), which `isStackNotDeployed` mistakes for "never deployed yet — skipped"
16162
+ * — a misleading green pass that hides an UNCHECKED stack. Worse, if a SAME-NAMED stack happens
16163
+ * to exist in the reachable account, cdkrd would silently compare intent against the WRONG
16164
+ * account's live resources. Detecting the mismatch UP FRONT lets check skip accurately without
16165
+ * reading the wrong account.
16166
+ *
16167
+ * Rule: skip ONLY when BOTH accounts are known (concrete) AND they differ — a proven mismatch.
16168
+ * When either is undefined (an env-agnostic stack with no account pin, or STS could not resolve
16169
+ * the caller) we CANNOT prove a mismatch, so we do NOT skip — behavior is identical to today
16170
+ * (the stack is read; a real "not deployed" still surfaces as before). Pure (no AWS) + exported
16171
+ * for unit tests.
16172
+ */
16173
+ function classifyAccountMismatch(declaredAccount, callerAccount) {
16174
+ if (declaredAccount && callerAccount && declaredAccount !== callerAccount) return {
16175
+ skip: true,
16176
+ message: `stack is pinned to account ${declaredAccount} but the active credentials are for account ${callerAccount} — skipped (run with account-${declaredAccount} credentials to check it)`
16177
+ };
16178
+ return {
16179
+ skip: false,
16180
+ message: ""
16181
+ };
16182
+ }
15975
16183
  function safeStringifyJson(value) {
15976
16184
  const seen = /* @__PURE__ */ new WeakSet();
15977
16185
  const replacer = (_key, v) => {
@@ -16060,7 +16268,14 @@ async function runCheck(args) {
16060
16268
  const showProgress = !a.json && isInteractive();
16061
16269
  let callerAccount;
16062
16270
  let callerAccountResolved = false;
16063
- for (const [idx, { stackName, region, template }] of stacks.entries()) {
16271
+ const ensureCallerAccount = async (region) => {
16272
+ if (!callerAccountResolved) {
16273
+ callerAccount = await resolveCallerAccount(region);
16274
+ callerAccountResolved = true;
16275
+ }
16276
+ return callerAccount;
16277
+ };
16278
+ for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
16064
16279
  if (!region) {
16065
16280
  const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
16066
16281
  console.error(`error: ${stackName}: ${msg}`);
@@ -16070,6 +16285,13 @@ async function runCheck(args) {
16070
16285
  }
16071
16286
  const posPrefix = a.json ? "" : positionPrefix(idx, stacks.length);
16072
16287
  try {
16288
+ const mismatch = classifyAccountMismatch(account, await ensureCallerAccount(region));
16289
+ if (mismatch.skip) {
16290
+ console.error(`note: ${stackName}: ${mismatch.message}`);
16291
+ jsonError(stackName, region, mismatch.message);
16292
+ worst = Math.max(worst, a.strict ? 1 : 0);
16293
+ continue;
16294
+ }
16073
16295
  const sKey = synthKey(stackName, region);
16074
16296
  if (synthTemplates && !synthTemplates.has(sKey)) {
16075
16297
  console.error(`note: ${stackName}: not in the synth output — skipped (--pre-deploy)`);
@@ -16080,6 +16302,13 @@ async function runCheck(args) {
16080
16302
  const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, synthTemplates?.get(sKey), template));
16081
16303
  const { desired, schemas, liveByLogical } = gathered;
16082
16304
  let findings = gathered.findings;
16305
+ if (account && desired.accountId !== account) {
16306
+ const msg = `compared against account ${desired.accountId} but the stack is pinned to ${account} — skipped (run with account-${account} credentials to check it)`;
16307
+ console.error(`note: ${stackName}: ${msg}`);
16308
+ jsonError(stackName, region, msg);
16309
+ worst = Math.max(worst, a.strict ? 1 : 0);
16310
+ continue;
16311
+ }
16083
16312
  const nestedWarn = nestedStackWarning(desired.resources, stackName);
16084
16313
  if (nestedWarn) console.error(nestedWarn);
16085
16314
  if (a.json) {
@@ -16180,10 +16409,7 @@ async function runCheck(args) {
16180
16409
  worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
16181
16410
  } catch (e) {
16182
16411
  if (isStackNotDeployed(e)) {
16183
- if (!callerAccountResolved) {
16184
- callerAccount = await resolveCallerAccount(region);
16185
- callerAccountResolved = true;
16186
- }
16412
+ await ensureCallerAccount(region);
16187
16413
  if (hasBaselineForStack(stackName, region, callerAccount)) {
16188
16414
  const msg = "deployed baseline exists but the stack is gone — deleted out of band";
16189
16415
  const label = `${stackName} (${region})`;