Skip to content

fix(cli): refactor fails on stacks with bundled assets, even for pure construct moves - #1812

Open
go-to-k wants to merge 1 commit into
aws:mainfrom
go-to-k:fix-refactor-bundling
Open

fix(cli): refactor fails on stacks with bundled assets, even for pure construct moves#1812
go-to-k wants to merge 1 commit into
aws:mainfrom
go-to-k:fix-refactor-bundling

Conversation

@go-to-k

@go-to-k go-to-k commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1810

Problem

BUNDLING_COMMANDS in packages/aws-cdk/lib/cli/user-configuration.ts is the explicit list of CLI commands that perform asset bundling during synthesis. refactor is not in it, so the synthesis performed by cdk refactor skips bundling for all stacks. For bundled assets like NodejsFunction, the asset hash (and therefore the S3Key in the synthesized template) is then computed from the source directory instead of the bundled output, so it differs from the deployed template. The refactor operation sees this as a property modification and CloudFormation rejects it:

❌  Refactor failed: Refactor creation: [CREATE_COMPLETE] Property changes detected during execution of refactor action <uuid> for refactor <uuid>

This happens even for a pure construct-tree move with no code changes. import was deliberately added to this list for the same reason (it also compares the synthesized template against the deployed one); refactor was added later and never included.

Fix

Add Command.REFACTOR to BUNDLING_COMMANDS, so that the synthesis performed by cdk refactor bundles assets the same way cdk deploy does, and the synthesized template matches the deployed one when nothing but the construct tree changed.

Testing

  • New unit test in test/cli/configuration.test.ts: bundlingStacks defaults to ['**'] for the refactor command (same pattern as the existing deploy/watch tests).
  • Verified against a real AWS environment, with a deployed stack containing a NodejsFunction moved into a new construct scope (no code changes):
    • CLI 2.1135.0 (released): the refactor execution fails with the error above (the stack rolls back and stays on the old logical IDs).
    • This branch: the same refactor succeeds end-to-end; the finalizing deployment reports no changes and the resources are on their new logical IDs afterwards:
Refactoring...
✅  Stack refactor complete
Deploying updated stacks to finalize refactor...
...
✅  RefactorBundlingRepro (no changes)

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

@go-to-k
go-to-k deployed to automation August 11, 2026 05:56 — with GitHub Actions Active
@go-to-k
go-to-k deployed to automation August 11, 2026 05:56 — with GitHub Actions Active
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 11, 2026 05:56
@github-actions github-actions Bot added the p2 label Aug 11, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.32%. Comparing base (785506e) to head (69f4f5b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1812   +/-   ##
=======================================
  Coverage   90.32%   90.32%           
=======================================
  Files          80       80           
  Lines       12124    12125    +1     
  Branches     1716     1716           
=======================================
+ Hits        10951    10952    +1     
  Misses       1139     1139           
  Partials       34       34           
Flag Coverage Δ
suite.unit 90.32% <100.00%> (+<0.01%) ⬆️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(refactor): fails on stacks with bundled assets, even for pure construct moves

2 participants