From 8703d0627667d9314553fa587f4483e019815890 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Sat, 11 Apr 2026 17:16:37 -0300 Subject: [PATCH] fix(tui): require absolute github cli path Ignore relative and empty `PATH` entries when resolving `gh`, then cache only a canonical executable path. This prevents PR lookups from executing a repo-relative binary after changing the command cwd. --- codex-rs/tui/src/github_pr.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/github_pr.rs b/codex-rs/tui/src/github_pr.rs index fbc6ab09b5..0ee19acb1a 100644 --- a/codex-rs/tui/src/github_pr.rs +++ b/codex-rs/tui/src/github_pr.rs @@ -103,8 +103,10 @@ fn resolve_gh_path_from_path(path_env: Option<&OsStr>) -> Option { path_env .into_iter() .flat_map(std::env::split_paths) + .filter(|dir| dir.is_absolute()) .flat_map(|dir| gh_executable_names().map(move |name| dir.join(name))) .find(|path| is_executable_file(path)) + .and_then(|path| path.canonicalize().ok()) } #[cfg(windows)] @@ -202,6 +204,23 @@ mod tests { let resolved = resolve_gh_path_from_path(Some(temp.path().as_os_str())); - assert_eq!(resolved, Some(gh)); + assert_eq!( + resolved, + Some(gh.canonicalize().expect("canonical gh path")) + ); + } + + #[test] + fn ignores_relative_path_entries() { + let resolved = resolve_gh_path_from_path(Some(OsStr::new("relative/bin"))); + + assert_eq!(resolved, None); + } + + #[test] + fn ignores_empty_path_entries() { + let resolved = resolve_gh_path_from_path(Some(OsStr::new(""))); + + assert_eq!(resolved, None); } }