fix(cloudformation-diff): DependsOn changes are invisible for lists of two or more - #1825
Merged
aws-cdk-automation merged 1 commit intoAug 18, 2026
Conversation
Adityaj0
had a problem deploying
to
integ-approval
August 12, 2026 08:32 — with
GitHub Actions
Failure
aws-cdk-automation
enabled auto-merge
August 12, 2026 08:32
mrgrain
approved these changes
Aug 18, 2026
…f two or more `dependsOnEqual` intends to compare two DependsOn arrays irrespective of element order, but the inner loop ends in an unconditional `break`, so it only ever runs for j = 0. The `return false` is guarded by `j === lvalue.length - 1`, which for any array longer than one element is never true on that single iteration. Two same-length arrays therefore always compare as equal, whatever they contain. The effect is that `cdk diff` reports no change for a resource whose DependsOn list is completely rewritten, as long as the number of entries stays the same. Replace the loop with a multiplicity-preserving match of each element on the left against a distinct element on the right. Neither input array is reordered, keeping the property that aws#1602 established. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mrgrain
force-pushed
the
fix/diff-dependson-multi-element
branch
from
August 18, 2026 15:02
d2a4a92 to
a8f9574
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1825 +/- ##
==========================================
+ Coverage 90.91% 90.92% +0.01%
==========================================
Files 80 80
Lines 12226 12226
Branches 1750 1750
==========================================
+ Hits 11115 11117 +2
+ Misses 1075 1073 -2
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1822
Reason for this change
dependsOnEqualcompares twoDependsOnarrays "irrespective of element order", but the inner loop ends in an unconditionalbreak, so it only ever runs forj = 0. Its singlereturn falseis guarded byj === lvalue.length - 1, which on that one iteration is only true for a one-element array. Any two same-length arrays with two or more entries therefore compare as equal, whatever they contain — the length check is the only comparison that survives.The user-visible effect:
cdk diffreports no change for a resource whose dependency list was rewritten, as long as the entry count stays the same. CDK emits multi-elementDependsOnroutinely (a singlelambda.Functionproduces two entries, as #1602 noted), so this is a realistic shape.Description of changes
Replaced the loop with a multiplicity-preserving match: each element on the left must find a distinct, not-yet-consumed element on the right. That is the order-insensitive comparison the original comment describes, and it also handles duplicates correctly (
['A','A']vs['A','B']is now unequal).Neither input array is reordered — only a local array of indices is mutated — so the no-mutation property established by #1575 / #1602 is preserved. There is an explicit test for that.
The three behaviours the suite already covered are unchanged: reordering is equal, differing lengths are unequal, and
'A'vs['A']is equal (handled by the branch above this one).This surfaces changes that
cdk diffcurrently hides. It does not invent differences: every newly reported change is a real edit to the template.Description of how you validated changes
template-and-changeset-diff-merger.test.ts, next to the existingDependsOncases: four parameterised cases for same-length-but-different arrays (2 elements fully replaced, 2 elements partially replaced, 3 elements, and a duplicate-sensitivity case), plus one asserting reorder-equality with no mutation of the caller's arrays.mainand pass with this change — confirmed by stashing thelibchange and re-running.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license