Skip to content

fix(core): stop injecting color env into test workers - #1893

Merged
fi3ework merged 3 commits into
mainfrom
fix/core-color-ownership
Sep 24, 2026
Merged

fi3ework merged 3 commits into
mainfrom
fix/core-color-ownership

Conversation

@fi3ework

@fi3ework fi3ework commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Motivation

Rstest injected FORCE_COLOR=1 (or NO_COLOR=1 + FORCE_COLOR=0 in agent sessions) into test worker processes so that its own worker-rendered diffs stayed colored. Code under test shares that process.env, so styleText, chalk and picocolors in 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

  • Rstest never writes FORCE_COLOR / NO_COLOR into any child env. Pool workers and the globalSetup worker are spawned with the host env as-is; config env is applied by setupEnv only.
  • The host resolves one boolean for its own output (resolveColorEnabled: NO_COLOR → off, FORCE_COLOR → on unless 0/false, agent session → off, otherwise picocolors detection). Each task gets the same rule applied to its projected env (host + project env), so env: { NO_COLOR: '1' } in config still keeps worker-rendered diff lines plain while host output follows the host env.
  • Workers apply the flag to Rstest's own picocolors instance and to the bundled tinyrainbow default instance before renderers load. tinyrainbow is aliased to the copy resolved from @vitest/utils in rslib.config.ts, so the toggle also reaches @vitest/utils diffs and @vitest/expect matcher messages.
  • environmentKey keeps the raw FORCE_COLOR / NO_COLOR segment so isolate: false workers 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):

Scenario Color env Rstest adds to worker process.env (what test files see): before → after Rstest diff / reporter output: before → after
Host on a TTY FORCE_COLOR=1 → nothing colored → colored
CI=true, piped FORCE_COLOR=1 → nothing (styleText now returns plain text) colored → colored
Piped, non-CI, non-agent nothing → nothing diff colored, header plain → all plain
Agent session NO_COLOR=1 + FORCE_COLOR=0 → nothing plain → plain
Host NO_COLOR / FORCE_COLOR set inherited → inherited follows it → follows it
Config env: { NO_COLOR: '1' }, CI=true nothing (since #1775) → nothing diff plain → diff plain, header follows host env

Which switch controls what after this change:

Switch Worker process.env (test files) Rstest diff / matcher message (rendered in worker) Rstest reporter (rendered on host)
Shell NO_COLOR / FORCE_COLOR inherited follows it follows it
Config env: { NO_COLOR: '1' } set by setupEnv follows it unaffected, follows host env
Agent session (RSTEST_NO_AGENT=1 opts out) untouched off off
Nothing set untouched picocolors detection on the host (TTY / CI / win32) same

There is no switch that changes Rstest's own colors without also reaching the worker env; a dedicated color option (#1767) is out of scope here.

Downstream repos currently carry workarounds for the injection. Once this lands they can be removed:

Repo File Workaround
rsbuild scripts/config/test.ts env: { FORCE_COLOR: '0' }
rsdoctor scripts/config/test.ts env: { FORCE_COLOR: '0' }
rsbuild-plugin-check-syntax rstack.config.ts env: { FORCE_COLOR: '0' }
rslib packages/plugin-dts/rstest.config.ts process.env.NO_COLOR = '1'
rstack-cli packages/rstack/rstack.config.ts process.env.NO_COLOR = '1'
rstack-cli packages/rstack/tests/cli/fmt/helpers.ts delete env.FORCE_COLOR

Tests: unit table for resolveColorEnabled; e2e for host NO_COLOR / agent / piped output, project NO_COLOR keeping diff lines plain under CI, and isolate: false color affinity. Known untested: the flag turning worker colors on when the worker's own detection says off (needs a pty). No docs change.

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T08:12:36.604489Z 47c541a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (6b96760a9a) does not have baseline artifacts. Using commit 56da003dda for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

Found 13 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 6.1 KB 0
adapter-rslib 51.1 KB 0
adapter-rspack 12.4 KB 0
browser 1.1 MB 0
browser-react 6.4 KB 0
coverage-istanbul 20.1 KB 0
coverage-v8 82.2 KB 0
playwright 54.0 KB 0
browser/client 80.1 KB 0
core/browser 645.3 KB -1.6 KB (-0.2%)
core/main 2.1 MB +975.0 B (0.0%)
vscode/extension 1.3 MB +11.9 KB (0.9%)
vscode/worker 19.2 KB 0
📋 Detailed Reports (Click to expand)

📁 core/browser

Path: packages/core/.rsdoctor/browser/rsdoctor-data.json

📌 Baseline Commit: 56da003dda | PR: #1888

Metric Current Baseline Change
📊 Total Size 645.3 KB 646.9 KB -1.6 KB (-0.2%)
📄 JavaScript 478.9 KB 478.9 KB 0
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 166.4 KB 168.0 KB -1.6 KB (-1.0%)

📦 Download Diff Report: core/browser Bundle Diff

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 56da003dda | PR: #1888

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB +975.0 B (0.0%)
📄 JavaScript 1.6 MB 1.6 MB +2.7 KB (0.2%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 441.0 KB 442.7 KB -1.8 KB (-0.4%)

📦 Download Diff Report: core/main Bundle Diff

📁 vscode/extension

Path: packages/vscode/.rsdoctor/extension/rsdoctor-data.json

📌 Baseline Commit: 56da003dda | PR: #1888

Metric Current Baseline Change
📊 Total Size 1.3 MB 1.3 MB +11.9 KB (0.9%)
📄 JavaScript 483.3 KB 472.6 KB +10.7 KB (+2.3%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 856.1 KB 854.9 KB +1.2 KB (0.1%)

📦 Download Diff Report: vscode/extension Bundle Diff

Generated by Rsdoctor GitHub Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Rstest forces FORCE_COLOR=1 on code under test because diffs are rendered inside workers

1 participant

Sponsor
SponsoredKunjungi sekarang
Promo