Skip to content

test(settings): handle TERM_PROGRAM env var in no_animations_env_reco…#2171

Merged
Hmbown merged 2 commits into
Hmbown:mainfrom
hongqitai:fix-test
May 26, 2026
Merged

test(settings): handle TERM_PROGRAM env var in no_animations_env_reco…#2171
Hmbown merged 2 commits into
Hmbown:mainfrom
hongqitai:fix-test

Conversation

@hongqitai
Copy link
Copy Markdown

@hongqitai hongqitai commented May 26, 2026

…gnises_truthy_spellings_only

Summary

Clear and restore TERM_PROGRAM environment variable during tests to prevent low_motion being forced in vscode, ghostty and Termius.

Problem

The test "codewhale_tui::settings::tests::no_animations_env_recognises_truthy_spellings_only" fails on some terminals, such as vscode, ghostty and Termius.

Root Cause

When TERM_PROGRAM is set to vscode, ghostty, or Termius, low_motion is enforced, causing the test to fail, and TERM_PROGRAM is not cleared before the test.

Fix

  • Add prev_term_program to save var of TERM_PROGRAM.
  • Clear TERM_PROGRAM before test.
  • Cleanup TERM_PROGRAM under the guard.

Additional Notes

The Cargo Clippy check has completed. These changes did not introduce any new warnings. However, some existing warnings were detected.

warning: used consecutive `str::replace` call
    --> crates/tui/src/config.rs:2914:10
     |
2914 |           .replace('-', "_")
     |  __________^
2915 | |         .replace(' ', "_")
     | |__________________________^ help: replace with: `replace(['-', ' '], "_")`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_str_replace
     = note: `#[warn(clippy::collapsible_str_replace)]` on by default

warning: `codewhale-tui` (bin "codewhale-tui") generated 1 warning (run `cargo clippy --fix --bin "codewhale-tui" -p codewhale-tui -- ` to apply 1 suggestion)
warning: this creates an owned instance just for comparison
   --> crates/tui/src/commands/goal.rs:166:31
    |
166 |                 if content == "Implement login flow".to_string()
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"Implement login flow"`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#cmp_owned
    = note: `#[warn(clippy::cmp_owned)]` on by default

warning: `codewhale-tui` (bin "codewhale-tui" test) generated 2 warnings (1 duplicate) (run `cargo clippy --fix --bin "codewhale-tui" -p codewhale-tui --tests -- ` to apply 1 suggestion)

Testing

  • [ x ] cargo fmt --all -- --check
  • [ x ] cargo clippy --workspace --all-targets --all-features
  • [ x ] cargo test --workspace --all-features

Checklist

  • [ x ] Updated docs or comments as needed
  • [ x ] Added or updated tests where relevant
  • [ x ] Verified TUI behavior manually if UI changes

Greptile Summary

This PR fixes test failures in no_animations_env_recognises_truthy_spellings_only that occurred in terminals such as VS Code, Ghostty, and Termius, where environment variables (TERM_PROGRAM, SSH_CLIENT, SSH_TTY, TILIX_ID, TERMINATOR_UUID) independently trigger low_motion, causing false assertion failures.

  • Saves and clears all five newly-relevant env vars before the test loops, consistent with the existing TMUX/STY handling pattern.
  • Restores each variable in the cleanup block (matching the save/remove idiom already used for WT_SESSION, TMUX, STY).

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to one test function and correctly covers all env vars that apply_env_overrides checks for low_motion.

The fix is complete: every environment variable that apply_env_overrides reads to set low_motion (TERM_PROGRAM, SSH_CLIENT, SSH_TTY, TILIX_ID, TERMINATOR_UUID, plus the pre-existing TMUX/STY) is now saved, cleared, and restored around the assertion loops. The implementation follows the established pattern in the test exactly, no production code is touched, and the pre-existing panic-safety concern is unchanged and well-understood.

No files require special attention — only one test function in crates/tui/src/settings.rs was modified.

Important Files Changed

Filename Overview
crates/tui/src/settings.rs Saves, clears, and restores TERM_PROGRAM, SSH_CLIENT, SSH_TTY, TILIX_ID, and TERMINATOR_UUID around the truthy-spellings test, covering all env vars that apply_env_overrides checks for low_motion. Change is consistent with existing test patterns and covers all relevant variables.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant E as Environment
    participant S as Settings::apply_env_overrides

    T->>E: save TMUX, STY, TERM_PROGRAM, SSH_CLIENT, SSH_TTY, TILIX_ID, TERMINATOR_UUID
    T->>E: remove_var(all above)
    loop truthy spellings ["1","true","YES","on","True"]
        T->>E: set_var(NO_ANIMATIONS, truthy)
        T->>S: apply_env_overrides()
        S-->>T: "low_motion = true ✓"
    end
    loop falsy spellings ["0","false","no","off",""]
        T->>E: set_var(NO_ANIMATIONS, falsy)
        T->>S: apply_env_overrides()
        S-->>T: "low_motion = false ✓"
    end
    T->>E: remove_var(NO_ANIMATIONS)
    T->>E: restore all saved vars
Loading

Comments Outside Diff (1)

  1. crates/tui/src/settings.rs, line 1356-1375 (link)

    P2 Cleanup skipped on assertion panic

    If any assert! inside the truthy/falsy loops fires, the function unwinds before reaching the cleanup block, leaving TERM_PROGRAM (and TMUX, STY, NO_ANIMATIONS) removed from the environment permanently for the rest of the test process. The MutexGuard _g is dropped correctly via unwind, but that only releases the lock — it does not restore the env vars.

    This is a pre-existing issue that affects all the env vars managed in this test. The TERM_PROGRAM addition is consistent with the existing pattern, but none of them are panic-safe. Wrapping the state in a custom Drop guard (one struct that holds all the prev_* values and restores them on drop) would make the entire group panic-safe and could replace the manual cleanup block.

    Fix in Codex Fix in Claude Code Fix in Cursor

Reviews (2): Last reviewed commit: "test(settings): handle other environment..." | Re-trigger Greptile

…gnises_truthy_spellings_only

Clear and restore TERM_PROGRAM environment variable during tests
to prevent low_motion being forced in vscode, ghostty and Termius.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the TUI settings tests to save, clear, and restore the TERM_PROGRAM environment variable, preventing it from interfering with NO_ANIMATIONS tests in environments like VS Code, Ghostty, or Termius. The reviewer suggests extending this logic to also handle other environment variables that can independently force low_motion (such as SSH_CLIENT, SSH_TTY, TILIX_ID, and TERMINATOR_UUID) to ensure test reliability across different environments.

Comment thread crates/tui/src/settings.rs
Comment thread crates/tui/src/settings.rs
…ntly force low_motion in no_animations_env_recognises_truthy_spellings_only
@Hmbown Hmbown merged commit 6bd702d into Hmbown:main May 26, 2026
2 checks passed
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.

2 participants