misc: correct newline wrapping in logs for strings with ANSI codes#33283
misc: correct newline wrapping in logs for strings with ANSI codes#33283mschile merged 4 commits intocypress-io:developfrom
Conversation
|
This comment was marked as outdated.
This comment was marked as outdated.
0efbd03 to
0e959e8
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This comment was marked as resolved.
This comment was marked as resolved.
|
Hi @mschile, I was asked to tag you on PRs I'd like reviewed. The one here principally benefits use of Cypress in GitHub Actions where the path to the location of Node.js is long enough to mess up the Cypress header log display. The issue has been around for a while and I only recently got around to analyzing the issue and proposing a fix. |
Handles strings containing ANSI escape code sequences If printable string length is within allowed width, does not wrap Converts strings to plain string without ANSI escape code sequences when printable width exceeded, then wraps accordingly Resolves issue displaying longer Node.js paths such as encountered on GitHub Actions in Ubuntu and macOS runners
8026e23 to
34d664b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Thank you very much for merging! I rechecked in the I would like to test it in GitHub Actions before the release. Unfortunately the pre-release build for the commit 877cad2 is only partially available. Executing Perhaps the cache needs some attention? |
|
@MikeMcC399, I purged the cache if you want to try again. |
|
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |



Additional details
The log header when Cypress is run, shows the Node Version with path.
In the CI environment of GitHub Actions runners, the paths are longer than on a typical non-CI installation:
macos-15/Users/runner/actions-runner/cached/externals/node24/bin/nodeubuntu-24.04/home/runner/actions-runner/cached/externals/node24/bin/nodewindows-2025C:\actions-runner\cached\externals\node24\bin\node.exeThis results in characters from ANSI escape code sequences being visibly printed to the logs for
macos-15andubuntu-24.04macos-15ubuntu-24.04The shorter path encountered on
windows-2025does not suffer from this issue, and the path is rendered correctly in the log header.The packages/server/lib/util/newlines.js utility is enhanced so that it correctly deals with strings containing ANSI escape sequences, such as created by the chalk package. In the case of Cypress run log headers, the text is being set to gray with ANSI escape sequences.
Before checking if a newline is needed, the string to be printed is stripped of any (non-printable) ANSI escape sequences.
If the string then needs wrapping with a newline, the string is returned wrapped without the ANSI escape sequences. This is necessary because in the Cypress run log header, the string is embedded in a table and even if the newline character (
\n) is added to the string without overwriting an ANSI escape sequence, only the first line of the string would be displayed as desired. Following lines have had their color status separately reset.This resolves the issue #32736 for GitHub Actions, since the Node.js paths can be displayed in the table within the available space. They were however getting incorrectly wrapped because newlines.js was counting the non-printing characters of the ANSI escape sequences as printing characters.
Note
Low Risk
Small, localized formatting change to a newline-wrapping utility plus targeted unit tests and a changelog entry; risk is limited to minor log output differences.
Overview
Fixes log header wrapping for strings containing ANSI/VT control codes (eg chalk-colored Node.js paths) by stripping non-printable characters before deciding where to insert newlines, and falling back to returning the original string unchanged when it would fit.
Updates unit coverage in
newlines_spec.tsto include length edge cases and ANSI-containing strings, and documents the user-visible behavior change incli/CHANGELOG.mdfor GitHub Actions environments.Written by Cursor Bugbot for commit 38cccfd. This will update automatically on new commits. Configure here.
Steps to test
On Windows 11 install Node.js 22.19.0 https://nodejs.org/dist/v22.19.0/node-v22.19.0-x64.msi to
C:\Program Files\home-runner-actions-runner-cachedD\to simulate the Ubuntu path length/home/runner/actions-runner/cached/externals/node24/bin/node, sincenode.exeis added to the original path.How has the user experience changed?
Users of GitHub Actions with Ubuntu or macOS runners will no longer see printed ANSI escape characters in the log header in the Node Version line.
This may also affect other CI providers and could occur if Node.js is installed elsewhere with a longer path. When Node.js is installed locally and default locations are used, the issue would not occur.
PR Tasks
cypress-documentation?type definitions?