Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Stop identifying Apple Terminal from `TERM_SESSION_ID` (#53438)

Eric Traut7c1b64c5df07
diff --git a/codex-rs/terminal-detection/src/lib.rs b/codex-rs/terminal-detection/src/lib.rs
index 2c172ee778..823a180ab2 100644
--- a/codex-rs/terminal-detection/src/lib.rs
+++ b/codex-rs/terminal-detection/src/lib.rs
@@ -248,7 +248,8 @@ pub fn terminal_info() -> TerminalInfo {
/// - `TERM_PROGRAM` (plus `TERM_PROGRAM_VERSION`) drives the detected terminal name,
/// except when it identifies tmux rather than the underlying terminal.
/// This means `TERM_PROGRAM` can mask later probes (for example `WT_SESSION`).
-/// - Next, terminal-specific variables (WEZTERM, iTerm2, Apple Terminal, kitty, etc.) are checked.
+/// - Next, terminal-specific variables (WEZTERM, iTerm2, kitty, etc.) are checked.
+/// `TERM_SESSION_ID` is not terminal-specific and cannot identify Apple Terminal.
/// - Finally, `TERM` is used as the capability fallback.
fn detect_terminal_info_from_env(env: &dyn Environment) -> TerminalInfo {
let multiplexer = detect_multiplexer(env);
@@ -274,14 +275,6 @@ fn detect_terminal_info_from_env(env: &dyn Environment) -> TerminalInfo {
return TerminalInfo::from_name(TerminalName::Iterm2, /*version*/ None, multiplexer);
}
- if env.has("TERM_SESSION_ID") {
- return TerminalInfo::from_name(
- TerminalName::AppleTerminal,
- /*version*/ None,
- multiplexer,
- );
- }
-
if env.has("KITTY_WINDOW_ID")
|| env
.var("TERM")
diff --git a/codex-rs/terminal-detection/src/terminal_tests.rs b/codex-rs/terminal-detection/src/terminal_tests.rs
index b761a767cc..49d5d1583e 100644
--- a/codex-rs/terminal-detection/src/terminal_tests.rs
+++ b/codex-rs/terminal-detection/src/terminal_tests.rs
@@ -153,14 +153,17 @@ fn detects_iterm2() {
#[test]
fn detects_apple_terminal() {
- let env = FakeEnvironment::new().with_var("TERM_PROGRAM", "Apple_Terminal");
+ let env = FakeEnvironment::new()
+ .with_var("TERM_PROGRAM", "Apple_Terminal")
+ .with_var("TERM_PROGRAM_VERSION", "455")
+ .with_var("TERM_SESSION_ID", "A1B2C3");
let terminal = detect_terminal_info_from_env(&env);
assert_eq!(
terminal,
terminal_info(
TerminalName::AppleTerminal,
Some("Apple_Terminal"),
- /*version*/ None,
+ Some("455"),
/*term*/ None,
/*multiplexer*/ None,
),
@@ -168,28 +171,9 @@ fn detects_apple_terminal() {
);
assert_eq!(
terminal.user_agent_token(),
- "Apple_Terminal",
+ "Apple_Terminal/455",
"apple_term_program_user_agent"
);
-
- let env = FakeEnvironment::new().with_var("TERM_SESSION_ID", "A1B2C3");
- let terminal = detect_terminal_info_from_env(&env);
- assert_eq!(
- terminal,
- terminal_info(
- TerminalName::AppleTerminal,
- /*term_program*/ None,
- /*version*/ None,
- /*term*/ None,
- /*multiplexer*/ None
- ),
- "apple_term_session_id_info"
- );
- assert_eq!(
- terminal.user_agent_token(),
- "Apple_Terminal",
- "apple_term_session_id_user_agent"
- );
}
#[test]
@@ -735,7 +719,9 @@ fn detects_vte() {
#[test]
fn detects_windows_terminal() {
- let env = FakeEnvironment::new().with_var("WT_SESSION", "1");
+ let env = FakeEnvironment::new()
+ .with_var("WT_SESSION", "1")
+ .with_var("TERM_SESSION_ID", "A1B2C3");
let terminal = detect_terminal_info_from_env(&env);
assert_eq!(
terminal,
@@ -778,7 +764,9 @@ fn detects_windows_terminal() {
#[test]
fn detects_term_fallbacks() {
- let env = FakeEnvironment::new().with_var("TERM", "xterm-256color");
+ let env = FakeEnvironment::new()
+ .with_var("TERM", "xterm-256color")
+ .with_var("TERM_SESSION_ID", "A1B2C3");
let terminal = detect_terminal_info_from_env(&env);
assert_eq!(
terminal,