Skip to content

worker: propagate TTY color support - #65776

Open
kiliczsh wants to merge 2 commits into
nodejs:mainfrom
kiliczsh:fix-worker-styletext-colors
Open

worker: propagate TTY color support#65776
kiliczsh wants to merge 2 commits into
nodejs:mainfrom
kiliczsh:fix-worker-styletext-colors

Conversation

@kiliczsh

@kiliczsh kiliczsh commented Sep 4, 2026

Copy link
Copy Markdown

Fixes: #65766

Description

util.styleText() checks the target stream to determine whether colors are
supported. In a worker, the default process.stdout and process.stderr are
worker stdio wrappers that do not expose the TTY color capabilities of the
parent destination. As a result, styleText() omits ANSI styling even when the
worker output is forwarded to a color-capable terminal.

This change propagates the parent stdout and stderr TTY state when a worker is
created with the default stdio handling. The worker then exposes the relevant
TTY color methods on its stdio wrapper, allowing styleText() to perform its
normal color-support check.

Workers created with stdout: true or stderr: true do not inherit the
corresponding TTY state. Their output is captured and its eventual destination
is unknown, so color is not enabled automatically in that case.

Testing

Added a regression test covering both cases:

  • default worker stdout forwarded to a color-capable parent;
  • worker stdout captured with stdout: true.

The following targeted tests pass on Windows:

python tools/test.py --mode=release parallel/test-util-styletext-worker parallel/test-util-styletext parallel/test-worker-stdio

Note: A broader test/parallel run completed with 4,845 passing tests and five
environment-related failures. None of those failures involved worker stdio or
styleText().

AI assistance was used while investigating the issue and preparing the change.
The code and tests were reviewed and verified by @kiliczsh(me).

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API. labels Sep 4, 2026
@kiliczsh
kiliczsh force-pushed the fix-worker-styletext-colors branch from 976abd0 to 4319228 Compare September 4, 2026 07:40
Propagate parent stdout and stderr TTY state to workers that use
default stdio handling. This allows styleText() to detect color support
inside workers.

Keep captured worker output unstyled because its eventual destination
is unknown.

Fixes: nodejs#65766

Signed-off-by: Muhammed Kılıç <[email protected]>
@kiliczsh
kiliczsh force-pushed the fix-worker-styletext-colors branch from 4319228 to 182c1fb Compare September 4, 2026 07:42
Cover stdout, stderr, captured streams, and non-TTY parent output.

Fixes: nodejs#65766
Signed-off-by: Muhammed Kılıç <[email protected]>
@kiliczsh

kiliczsh commented Sep 4, 2026

Copy link
Copy Markdown
Author

I pushed a follow-up commit that expands the regression coverage.

The test now covers:

  • inherited TTY behavior for both worker stdout and stderr;
  • captured stdout with stdout: true;
  • captured stderr with stderr: true;
  • default stdout when the parent is not a TTY;
  • the availability of isTTY, getColorDepth(), and hasColors().

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.05%. Comparing base (a1bfce9) to head (0344016).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65776      +/-   ##
==========================================
- Coverage   90.06%   90.05%   -0.02%     
==========================================
  Files         769      769              
  Lines      261321   261430     +109     
  Branches    49625    49638      +13     
==========================================
+ Hits       235369   235439      +70     
- Misses      16994    17031      +37     
- Partials     8958     8960       +2     
Files with missing lines Coverage Δ
lib/internal/main/worker_thread.js 95.35% <100.00%> (+0.44%) ⬆️
lib/internal/worker.js 97.03% <100.00%> (+<0.01%) ⬆️

... and 41 files with indirect coverage changes

🚀 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

needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

styleText() doesn't work within a worker thread

2 participants