(cli): cdk flags --set always reports no template differences before applying flags

未关闭
#2,153 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@go-to-k 已经在做这个了。

开始于 2026年11月15日。

  • #2154 来自 @go-to-k —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
aws, typescript

调研方向

Read packages/aws-cdk/lib/commands/flags/operations.ts, especially FlagOperations.prototypeChanges(), and trace when the app is synthesized and the context store is updated. Reproduce with the TypeScript CDK app and cdk flags --unstable=flags --set --unconfigured --recommended. Done when the preview diff includes the template changes made by the new flag values.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

cdk flags --unstable=flags --set ... (for example --unconfigured --recommended) is supposed to synthesize the app with the current flag values and with the new flag values, show the template diff between the two, and then ask for confirmation.

The diff it shows is always empty (There were no differences / Number of stacks with differences: 0), even for flags that change the template. After accepting, cdk synth shows that the template did change.

Reproduction

Confirmed with CLI 2.1145.0 / aws-cdk-lib 2.272.0.

  1. Create a project with cdk init app --language typescript
  2. Remove @aws-cdk/aws-lambda:useCdkManagedLogGroup from the context in cdk.json, and define one lambda.Function in the stack
  3. Run npx cdk flags --unstable=flags --set --unconfigured --recommended
    -> the diff says there are no differences
  4. Accept the changes and run npx cdk synth
    -> an AWS::Logs::LogGroup has been added (it is not in the synth before the change)
Expected behavior

The diff shown before the confirmation prompt includes the template changes caused by the new flag values (here, [+] AWS::Logs::LogGroup).

Root cause

FlagOperations.prototypeChanges() in packages/aws-cdk/lib/commands/flags/operations.ts:

const memoryContext = new MemoryContext(baseContextValues);
...
const source = await this.toolkit.fromCdkApp(app, {
  contextStore: memoryContext,
  outdir: this.originalTempDir,
});
...
await memoryContext.update(updateObj);
const cx = await this.toolkit.synth(source);
...
const modifiedSource = await this.toolkit.fromCdkApp(app, {
  contextStore: memoryContext,
  outdir: this.modifiedTempDir,
});
  • One MemoryContext is passed to both the "original" and the "modified" fromCdkApp() sources.
  • fromCdkApp() is lazy: the app is only synthesized, and the context store only read, at toolkit.synth(source).
  • memoryContext.update(updateObj) is called before the first synth.

So the "original" assembly is also synthesized with the new flag values, both assemblies are identical, and the diff is always empty.

主要语言
TypeScript
星标
110
派生
138
平均合并
1 天 9 小时
30 天内合并 PR
56

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aws/aws-cdk-cli 的其他 Issue

查看 aws/aws-cdk-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。