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.
This commit is contained in:
Felipe Coury
2026-04-11 17:16:37 -03:00
parent 5c9723574b
commit 8703d06276
+20 -1
View File
@@ -103,8 +103,10 @@ fn resolve_gh_path_from_path(path_env: Option<&OsStr>) -> Option<PathBuf> {
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);
}
}