Skip to content

fix(cloudformation-diff): handle removed resource metadata - #1741

Open
fukunaga-kengo wants to merge 3 commits into
aws:mainfrom
fukunaga-kengo:fix/issue-390-metadata-removal-diff
Open

fukunaga-kengo wants to merge 3 commits into
aws:mainfrom
fukunaga-kengo:fix/issue-390-metadata-removal-diff

Conversation

@fukunaga-kengo

@fukunaga-kengo fukunaga-kengo commented Jul 20, 2026 •

Copy link
Copy Markdown

Issue # (if applicable)

Fixes #390.

Fixes an assertion failure when a CloudFormation resource's Metadata is removed.

The template/change-set merger intentionally hides resource Metadata differences. It previously
did this by constructing a replacement difference from the new Metadata value twice. When Metadata
was removed, both values were undefined, violating the Difference invariant and throwing an
AssertionError.

The fix marks the existing Metadata difference as unchanged instead of constructing another
difference. This preserves the existing behavior of hiding Metadata-only changes and handles
additions, modifications, and removals uniformly.

Metadata removed
      |
      v
existing Difference(old, undefined)
      |
      v
isDifferent = false
      |
      v
no crash; Metadata remains hidden

Testing

  • Added a regression test that reproduced the AssertionError before the fix.
  • @aws-cdk/cloudformation-diff: 147 tests passed.
  • Package compile, lint, coverage, license check, and packaging passed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions Bot added bug effort/medium 1-3 days of effort p2 labels Jul 20, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team July 20, 2026 08:18
auto-merge was automatically disabled July 20, 2026 13:39

Pull request was closed

@fukunaga-kengo
fukunaga-kengo deleted the fix/issue-390-metadata-removal-diff branch July 20, 2026 13:39
@fukunaga-kengo
fukunaga-kengo restored the fix/issue-390-metadata-removal-diff branch July 20, 2026 13:39
@mrgrain

mrgrain commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@abhiramshaji-cyber @fukunaga-kengo Thanks for both of your fixes! I think each PR is missing a test case:

@codecov-commenter

codecov-commenter commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.08%. Comparing base (95683e3) to head (b0f9fe9).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1741   +/-   ##
=======================================
  Coverage   92.08%   92.08%           
=======================================
  Files          83       83           
  Lines       13246    13246           
  Branches     1886     1886           
=======================================
  Hits        12197    12197           
  Misses       1011     1011           
  Partials       38       38           
Flag Coverage Δ
suite.unit 92.08% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maintainer-for-aws

maintainer-for-aws Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Automated review

A maintainer will still review this — treat the notes below as a starting point.

📌 Commit b0f9fe9

This PR fixes a bug in the @aws-cdk/cloudformation-diff package where diffing two CloudFormation templates threw an AssertionError when a resource's Metadata block was removed. In TemplateAndChangeSetDiffMerger, Metadata changes were previously suppressed by constructing a no-op Difference(value.newValue, value.newValue); when Metadata is removed, newValue is undefined, so both constructor arguments were undefined, which the Difference constructor rejects. The fix replaces that construction with an in-place value.isDifferent = false, which the downstream onlyChanges filter already keys off of, so Metadata is suppressed from the visible and counted diff without invoking the throwing constructor. The change is minimal and behavior-preserving, mirrors the existing mutation pattern used for hidden property differences a few lines above, breaks no exported contract, and adds a parameterized regression test covering the removed, added, set-to-undefined, and added-over-undefined cases. No issues found on this change.

🔴 0 blocking · 🟡 0 recommended · ⚪ 0 optional


Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews.

@maintainer-for-aws maintainer-for-aws Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the review summary comment for the overview; the notes below are inline.

@mrgrain
mrgrain deployed to integ-approval October 30, 2026 17:16 — with GitHub Actions Active
@abhiramshaji-cyber

Copy link
Copy Markdown

Congrats @fukunaga-kengo on getting this fix in, and thanks @mrgrain for the thoughtful review and for folding the extra test cases into the table. Really glad the removed and added cases from #2106 could help round out the coverage 🙂

@fukunaga-kengo

Copy link
Copy Markdown
Author

Thanks @mrgrain for adding the extra test cases and reviewing this PR! Thanks also to @abhiramshaji-cyber for sharing the removal and addition tests from #2106. I really appreciate the help from both of you!

This branch had an error being deployed

1 failed, 1 active, and 1 inactive (outdated) deployments
run-tests — b0f9fe98 Deployed Oct 31, 2026 by mrgrain via integ_toolkit-lib (toolkit-lib-integ-tests, 24) #7538
integ-approval — b0f9fe98 Deployed Oct 30, 2026 by mrgrain via prepare #7538
automation — b2d6cdc4 Deployed Jul 20, 2026 by fukunaga-kengo via Triage Pull Requests #1873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(toolkit-lib): AssertionError [ERR_ASSERTION]: oldValue and newValue are both undefined!

4 participants