Skip to content

fix(core): align color env priority and improve agent detection#936

Merged
fi3ework merged 1 commit intomainfrom
max/2026-02-04--1-17AM
Feb 3, 2026
Merged

fix(core): align color env priority and improve agent detection#936
fi3ework merged 1 commit intomainfrom
max/2026-02-04--1-17AM

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Feb 3, 2026

Summary

  • Color Environment Handling
    • Adjust env merge order in worker pools to ensure user-defined FORCE_COLOR/NO_COLOR always overrides defaults
    • Refactor getForceColorEnv to automatically disable colors in AI agent environments by default
    • Synchronize FORCE_COLOR=0 when NO_COLOR=1 is detected to prevent conflicts in downstream tools
  • Agent Detection
    • Support RSTEST_NO_AGENT environment variable to explicitly opt-out of agent detection
    • Simplify repo self-testing setup by using the opt-out flag instead of manually clearing env vars
  • Code Health
    • Unify color support checks across core modules using isColorSupported

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings February 3, 2026 18:01
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: f72fa1e
Status: ✅  Deploy successful!
Preview URL: https://73d5aeb3.rstest.pages.dev
Branch Preview URL: https://max-2026-02-04--1-17am.rstest.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines how color-related environment variables are handled and adds explicit agent detection controls, with corresponding test coverage to lock in the new behavior.

Changes:

  • Centralizes color support handling in logger.ts, introduces getForceColorEnv that prefers user-provided env vars, and re-exports isColorSupported for use across core modules.
  • Adjusts worker/global setup pool environment merging so process.env overrides internal defaults, and defaults to plain output in AI agent environments (with RSTEST_NO_AGENT to opt out).
  • Adds and updates E2E tests to validate FORCE_COLOR/NO_COLOR propagation and to ensure agent-based Markdown reporting behavior remains correct.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/rstest.setup.ts Sets RSTEST_NO_AGENT=1 during repo self-tests to avoid mis-detecting the test runner as an AI agent.
packages/core/src/utils/logger.ts Re-exports isColorSupported and rewrites getForceColorEnv to honor user FORCE_COLOR, sync FORCE_COLOR=0 when NO_COLOR=1, and default to no-color in agent/unsupported environments.
packages/core/src/utils/agent/detectAgent.ts Adds RSTEST_NO_AGENT opt-out to force determineAgent() to report non-agent contexts when requested.
packages/core/src/pool/index.ts Changes worker pool env merge order so getForceColorEnv() defaults are overridden by the parent process.env.
packages/core/src/core/restart.ts Switches from ansiEnabled to isColorSupported for console clearing and wires through the new utils export.
packages/core/src/core/globalSetup.ts Aligns global-setup worker env merging with the new getForceColorEnv() semantics (defaults first, process.env last).
e2e/reporter/md.test.ts Introduces UNSET_ENV = ['RSTEST_NO_AGENT'] so these agent-reporting tests still exercise agent detection even though self-tests globally set RSTEST_NO_AGENT.
e2e/env/index.test.ts Adds E2E cases verifying that user-set FORCE_COLOR is preserved and that NO_COLOR=1 causes workers to see FORCE_COLOR=0 to avoid downstream conflicts.
e2e/env/fixtures/noColor.test.ts Asserts workers receive FORCE_COLOR=0 and NO_COLOR=1 when NO_COLOR=1 is configured.
e2e/env/fixtures/forceColor.test.ts Asserts workers see FORCE_COLOR=1 when it is explicitly set by the parent process.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fi3ework fi3ework enabled auto-merge (squash) February 3, 2026 18:15
@fi3ework fi3ework merged commit f10b3d5 into main Feb 3, 2026
25 of 27 checks passed
@fi3ework fi3ework deleted the max/2026-02-04--1-17AM branch February 3, 2026 18:17
@9aoy 9aoy mentioned this pull request Feb 5, 2026
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.

2 participants