fix(test): strip inherited color-forcing env vars in brew upgrade tests

The brew_command helper inherits the developer's environment (unlike
context.command(), which env_clears), so an exported FORCE_COLOR or
CLICOLOR_FORCE overrides the NO_COLOR=1 the harness sets and the CLI
renders ANSI codes into snapshot output, failing
upgrade_brew_install_refuses_and_prints_brew_command and
upgrade_brew_install_rejects_version_flag on any machine with
FORCE_COLOR exported.

Remove FORCE_COLOR, CLICOLOR_FORCE, and CLICOLOR from the spawned
command's env, and add the FORCE_COLOR constant to EnvVars.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-07-23 11:19:01 -04:00
parent f00a2ed1ea
commit edbd25f67c
No known key found for this signature in database
2 changed files with 8 additions and 0 deletions

View file

@ -49,6 +49,12 @@ fn brew_command(context: &TestContext, formula: &str, version: &str) -> Command
}
}
cmd.env(EnvVars::NO_COLOR, "1");
// Unlike context.command(), this command inherits the developer's
// environment, and inherited FORCE_COLOR/CLICOLOR_FORCE override NO_COLOR
// in the CLI's color detection — breaking these snapshots.
cmd.env_remove(EnvVars::FORCE_COLOR);
cmd.env_remove(EnvVars::CLICOLOR_FORCE);
cmd.env_remove(EnvVars::CLICOLOR);
cmd.env(EnvVars::HOME, &context.home_dir);
cmd.env(EnvVars::FABRO_NO_UPGRADE_CHECK, "true")
.env(EnvVars::FABRO_HTTP_PROXY_POLICY, "disabled")

View file

@ -114,6 +114,7 @@ impl EnvVars {
pub const CI: &'static str = "CI";
pub const CLICOLOR: &'static str = "CLICOLOR";
pub const CLICOLOR_FORCE: &'static str = "CLICOLOR_FORCE";
pub const FORCE_COLOR: &'static str = "FORCE_COLOR";
pub const HOME: &'static str = "HOME";
pub const KUBERNETES_SERVICE_HOST: &'static str = "KUBERNETES_SERVICE_HOST";
pub const LANG: &'static str = "LANG";
@ -251,6 +252,7 @@ mod tests {
EnvVars::CI,
EnvVars::CLICOLOR,
EnvVars::CLICOLOR_FORCE,
EnvVars::FORCE_COLOR,
EnvVars::HOME,
EnvVars::KUBERNETES_SERVICE_HOST,
EnvVars::LANG,