Repository navigation
(cli tests): refactor and destroy IO expectations differ by newlines on a clean CLI checkout #2085
Description
Describe the bug
On an unmodified aws/aws-cdk-cli checkout at df34416fefcbd5361b9fd3686307f718f3ac1ec1, the refactor and destroy unit tests fail against the committed IoHost recorded-output expectations. The observed differences include leading/trailing newlines in message strings.
This report concerns the test/output contract. I have not established whether the runtime output or the recorded expectations should change, and I am not claiming a deployed-resource regression.
Expected Behavior
The refactor/destroy tests pass against the committed recorded-output files on the documented supported Node.js version, without regenerating expected output simply to make the run pass.
Current Behavior
Running the two suites along with test/cli/cli.test.ts, with CI unset, produced 20 failed / 40 passed tests, two failing suites and one passing suite. The same refactor/destroy failures also occur with CI=true.
Example refactor difference:
- "message":"aws://123456789012/bermuda-triangle-1\n"
+ "message":"aws://123456789012/bermuda-triangle-1"Example destroy difference:
- "message":"\n✅ Test-Stack-A-Display-Name: destroyed"
+ "message":"✅ Test-Stack-A-Display-Name: destroyed"Failures include ambiguity > reports ambiguous mappings and refuses to refactor and force: true (no confirmation prompt) > destroys all top-level stacks with concurrency.
Reproduction Steps
Use a disposable checkout of aws/aws-cdk-cli at the commit above, Node.js 24.13.1 and its pinned Yarn 4.17.1. Install dependencies with corepack yarn install --immutable, then run the repository's topological corepack yarn compile (ensure the yarn shim is on PATH for child tasks). Both commands completed successfully here.
From packages/aws-cdk, run:
env -u CI TESTING_CDK=1 NODE_OPTIONS=--experimental-vm-modules \
node ../../node_modules/jest/bin/jest.js \
test/cli/cli.test.ts test/commands/refactor.test.ts test/commands/destroy.test.ts \
--ci --runInBand --coverage=falseDo not pass -u / --updateSnapshot. The command exits 1. The selected tests use mocked AWS calls; no deployment is needed.
Additional Information/Context
The 20 failures reported here were reproduced on the unmodified source commit specified above.
Related implementation history: #1661 added effective-message recording and aws/aws-cdk#1686 rerouted destroy through toolkit-lib. These are context, not a claim that either PR introduced the issue. Searches of issues in both CDK repositories and matching open PRs did not find an existing report of these test failures.
Last Known Working CDK Version
Unknown; not claiming a regression from a known passing version.
CDK CLI Version
Source checkout df34416fefcbd5361b9fd3686307f718f3ac1ec1; unit tests, not a published CLI release.
Node.js Version
v24.13.1
OS
Ubuntu 24.04 / WSL2, Linux 6.6.87.2-microsoft-standard-WSL2
Language
TypeScript 5.9.3; Jest 29.
Other information
AI assistance was used in the investigation and preparation of this report. Reproduction commands were executed; no expected-output files were changed.
Activity
pahud commentedon Oct 23, 2026
Hi @mkymdk,
Thanks for the careful report. I reproduced it on
df34416with your exact command (20 failed / 40 passed). WithFORCE_COLOR=1, all 60 pass, so the snapshots depend on whether chalk has color enabled.toolkit-lib trims every message, but with color on the
\nsits inside the ANSI codes, sotrim()leaves it alone. The recorder then strips the ANSI codes and the\nshows up:aws-cdk-cli/packages/@aws-cdk/toolkit-lib/lib/api/io/private/io-host-wrappers.ts
Lines 59 to 74 in df34416
CI runs the tests through
nx run-many, which setsFORCE_COLOR=truefor each task. That's why the committed snapshots pass there but not in a direct jest run. Pinning color in the aws-cdk jest setup would make the run deterministic. A PR is welcome if you're interested.This belongs in aws/aws-cdk-cli, so we'll transfer it there. Marking this as a p2 bug.
mkymdk commentedon Oct 24, 2026
Thanks @pahud for reproducing this and explaining the color-dependent behavior! I see that #2047 already addresses this. Thanks to @lazerg for the fix as well.
fix(toolkit-lib): whitespace is not trimmed from colored messages (aw…