fix(core): stop injecting color env into test workers - #1893
Conversation
Rstest wrote FORCE_COLOR/NO_COLOR into worker and globalSetup child env so its own worker-rendered diffs stayed colored. Code under test shares that process.env, so styleText/chalk/picocolors in user code produced ANSI under Rstest but not under plain Node. The host now resolves one color boolean for its own output and applies the same rule to each task's projected env (host + project env). Workers apply the flag to Rstest's picocolors instance and the bundled tinyrainbow instance before renderers load; no color env is written into any child process. Closes #1774
Rstest wrote FORCE_COLOR/NO_COLOR into worker and globalSetup child env so its own worker-rendered diffs stayed colored. Code under test shares that process.env, so styleText/chalk/picocolors in user code produced ANSI under Rstest but not under plain Node. The host now resolves one color boolean for its own output and applies the same rule to each task's projected env (host + project env). Workers apply the flag to Rstest's picocolors instance and the bundled tinyrainbow instance before renderers load; no color env is written into any child process. Closes #1774
This reverts commit 347a91b.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Rsdoctor Bundle Diff Analysis
Found 13 projects in monorepo, 3 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 core/browserPath:
📦 Download Diff Report: core/browser Bundle Diff 📁 core/mainPath:
📦 Download Diff Report: core/main Bundle Diff 📁 vscode/extensionPath:
📦 Download Diff Report: vscode/extension Bundle Diff Generated by Rsdoctor GitHub Action |
Motivation
Rstest injected
FORCE_COLOR=1(orNO_COLOR=1+FORCE_COLOR=0in agent sessions) into test worker processes so that its own worker-rendered diffs stayed colored. Code under test shares thatprocess.env, sostyleText,chalkandpicocolorsin user code produced ANSI under Rstest but not under plain Node — snapshot tests of CLI output passed locally and failed in CI.Closes #1774. Related: #1767 / #1775.
Changes
FORCE_COLOR/NO_COLORinto any child env. Pool workers and the globalSetup worker are spawned with the host env as-is; configenvis applied bysetupEnvonly.resolveColorEnabled:NO_COLOR→ off,FORCE_COLOR→ on unless0/false, agent session → off, otherwise picocolors detection). Each task gets the same rule applied to its projected env (host + project env), soenv: { NO_COLOR: '1' }in config still keeps worker-rendered diff lines plain while host output follows the host env.@vitest/utilsinrslib.config.ts, so the toggle also reaches@vitest/utilsdiffs and@vitest/expectmatcher messages.environmentKeykeeps the rawFORCE_COLOR/NO_COLORsegment soisolate: falseworkers are not reused across projects with different color env.restart.ts: clearing the screen on restart is gated on TTY only, no longer on color support.Behavior before / after (no user color env unless stated):
process.env(what test files see): before → afterFORCE_COLOR=1→ nothingCI=true, pipedFORCE_COLOR=1→ nothing (styleTextnow returns plain text)NO_COLOR=1+FORCE_COLOR=0→ nothingNO_COLOR/FORCE_COLORsetenv: { NO_COLOR: '1' },CI=trueWhich switch controls what after this change:
process.env(test files)NO_COLOR/FORCE_COLORenv: { NO_COLOR: '1' }setupEnvRSTEST_NO_AGENT=1opts out)There is no switch that changes Rstest's own colors without also reaching the worker env; a dedicated
coloroption (#1767) is out of scope here.Downstream repos currently carry workarounds for the injection. Once this lands they can be removed:
scripts/config/test.tsenv: { FORCE_COLOR: '0' }scripts/config/test.tsenv: { FORCE_COLOR: '0' }rstack.config.tsenv: { FORCE_COLOR: '0' }packages/plugin-dts/rstest.config.tsprocess.env.NO_COLOR = '1'packages/rstack/rstack.config.tsprocess.env.NO_COLOR = '1'packages/rstack/tests/cli/fmt/helpers.tsdelete env.FORCE_COLORTests: unit table for
resolveColorEnabled; e2e for hostNO_COLOR/ agent / piped output, projectNO_COLORkeeping diff lines plain under CI, andisolate: falsecolor affinity. Known untested: the flag turning worker colors on when the worker's own detection says off (needs a pty). No docs change.