Skip to content

fix(toolkit-lib): whitespace is not trimmed from colored messages - #2047

Merged
mrgrain merged 2 commits into
aws:mainfrom
lazerg:fix/io-snapshots-without-color
Oct 26, 2026
Merged

mrgrain merged 2 commits into
aws:mainfrom
lazerg:fix/io-snapshots-without-color

Conversation

@lazerg

@lazerg lazerg commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2085

The refactor and destroy IO snapshot tests pass in CI but fail when jest is run directly, as in npx jest test/commands/destroy.test.ts. The difference is color support. nx run-many sets FORCE_COLOR for every task, so in CI chalk wraps messages in color codes. The Toolkit trims whitespace around each message, but with color on, a leading or trailing newline sits inside the color codes and trim() does not see it. So colored messages keep the newline and plain ones lose it, and the committed snapshots only match the colored run.

withTrimmedWhitespace now also trims whitespace that sits between the color codes at either end of a message, and keeps the codes. Messages come out the same with or without color. I added a test for this in toolkit-lib and updated the 20 refactor/destroy snapshots, which now pass with FORCE_COLOR unset, 0 and 1.

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

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

@codecov-commenter

codecov-commenter commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.05%. Comparing base (df34416) to head (349575f).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2047      +/-   ##
==========================================
- Coverage   92.09%   92.05%   -0.05%     
==========================================
  Files          82       83       +1     
  Lines       13184    13246      +62     
  Branches     1877     1884       +7     
==========================================
+ Hits        12142    12193      +51     
- Misses       1004     1015      +11     
  Partials       38       38              
Flag Coverage Δ
suite.unit 92.05% <ø> (-0.05%) ⬇️

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.

Comment thread packages/aws-cdk/test/_helpers/io-recorder.ts Outdated
auto-merge was automatically disabled October 26, 2026 15:28

Head branch was pushed to by a user without write access

@lazerg lazerg changed the title test(cli): io snapshot tests fail when color is not supported fix(toolkit-lib): whitespace is not trimmed from colored messages Oct 26, 2026
@lazerg
lazerg deployed to integ-approval October 26, 2026 15:29 — with GitHub Actions Active
@maintainer-for-aws

Copy link
Copy Markdown

Automated review

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

📌 Commit 349575f

This PR fixes a color-dependent whitespace-trimming bug in the toolkit-lib message pipeline (io-host-wrappers.ts). Previously, withTrimmedWhitespace used String.prototype.trim(), which only looks at the literal ends of a message string; when color is enabled, chalk nests a leading/trailing newline inside ANSI style codes, so the newline was never trimmed. The new trimWhitespace helper splits on SGR style codes (text at even indices, codes at odd) and trims only the logical-end text segments, keeping the style codes and preserving interior whitespace. The result is deterministic output across color settings. A dedicated unit test covers the new behavior, and 20 .ndjson IO snapshots are updated to the normalized (color-agnostic) form — each a pure removal of leading/trailing newlines with no change to sequence, code, level, or structure. The change is small, single-concern, and well-targeted at the diagnosed root cause. 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.

@mrgrain
mrgrain added this pull request to the merge queue Oct 26, 2026
Merged via the queue into aws:main with commit f9172c7 Oct 26, 2026
56 checks passed

This branch was successfully deployed

1 active and 2 inactive (1 outdated) deployments
run-tests — 349575fc Deployed Oct 26, 2026 by lazerg via integ_toolkit-lib (toolkit-lib-integ-tests, 24) #7478
integ-approval — 349575fc Deployed Oct 26, 2026 by lazerg via prepare #7478
automation — f1008402 Deployed Oct 15, 2026 by lazerg via Set AutoQueue on PR #2047 #3746
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.

(cli tests): refactor and destroy IO expectations differ by newlines on a clean CLI checkout

3 participants