From 1da623dc822f68767cfc6b7281f0ac587423339b Mon Sep 17 00:00:00 2001 From: Victor Skvortsov Date: Mon, 3 Aug 2026 17:01:28 +0500 Subject: [PATCH] Pin rich to non-terminal output in tests Coding agents run with FORCE_COLOR set, which makes rich colorize even when stdout is a pipe, so CLI tests asserting on plain text failed for agents while passing locally and in CI. DSTACK_CLI_RICH_FORCE_TERMINAL could not prevent it because rich_argparse builds its own console for --help that dstack never constructs. TTY_COMPATIBLE=0 covers every rich console in the process and takes precedence over FORCE_COLOR, which makes the dstack-specific setting redundant. --- pyproject.toml | 4 +++- src/dstack/_internal/cli/utils/common.py | 11 ++--------- src/dstack/_internal/settings.py | 3 --- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 60b233223..efa7986c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,8 +133,10 @@ markers = [ "dockerized", ] env = [ - "DSTACK_CLI_RICH_FORCE_TERMINAL=0", "DSTACK_SSHPROXY_API_TOKEN=test-token", + # Pin every rich console in the process to non-terminal output so tests asserting on plain CLI + # text never see ANSI escapes. + "TTY_COMPATIBLE=0", ] filterwarnings = [ # Fail on any use of a pydantic v1 shim (`.dict()`, `parse_obj_as`, class-based `Config`, ...) diff --git a/src/dstack/_internal/cli/utils/common.py b/src/dstack/_internal/cli/utils/common.py index 21d5caf83..b8c160dfd 100644 --- a/src/dstack/_internal/cli/utils/common.py +++ b/src/dstack/_internal/cli/utils/common.py @@ -24,16 +24,9 @@ "code": "bold sea_green3", } -console = Console( - theme=Theme(_colors), - force_terminal=settings.CLI_RICH_FORCE_TERMINAL, -) +console = Console(theme=Theme(_colors)) -error_console = Console( - theme=Theme(_colors), - force_terminal=settings.CLI_RICH_FORCE_TERMINAL, - stderr=True, -) +error_console = Console(theme=Theme(_colors), stderr=True) LIVE_TABLE_REFRESH_RATE_PER_SEC = 1 diff --git a/src/dstack/_internal/settings.py b/src/dstack/_internal/settings.py index 3dd7acf65..594d92119 100644 --- a/src/dstack/_internal/settings.py +++ b/src/dstack/_internal/settings.py @@ -1,7 +1,6 @@ import os from dstack import version -from dstack._internal.utils.env import environ from dstack._internal.utils.version import parse_version DSTACK_VERSION = os.getenv("DSTACK_VERSION", version.__version__) @@ -33,8 +32,6 @@ CLI_LOG_LEVEL = os.getenv("DSTACK_CLI_LOG_LEVEL", "INFO").upper() CLI_FILE_LOG_LEVEL = os.getenv("DSTACK_CLI_FILE_LOG_LEVEL", "DEBUG").upper() -# Can be used to disable control characters (e.g. for testing). -CLI_RICH_FORCE_TERMINAL = environ.get_bool("DSTACK_CLI_RICH_FORCE_TERMINAL") class FeatureFlags: