Skip to content

Commit 4328d23

Browse files
committed
fix(rtk): normalize binary path to bare 'rtk' in rewrite_command
find_rtk_binary() returned the full absolute path when a bundled binary was found next to the exe (e.g. target/ci/deps/rtk), but bare 'rtk' when found via PATH. This caused rewrite_command to produce '/home/runner/.../rtk git status' instead of 'rtk git status' on Linux CI where a previous test run had auto-installed the binary. 5 rewrite tests failed. Fix: all three discovery paths (bundled, PATH, auto-download) now return bare 'rtk'. The binary's directory is prepended to PATH via ensure_dir_in_path() so the bare name resolves at exec time.
1 parent 8e98242 commit 4328d23

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/rtk/rewrite.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ pub(crate) fn rtk_bin_filename() -> &'static str {
131131
if cfg!(windows) { "rtk.exe" } else { "rtk" }
132132
}
133133

134+
/// Ensure a directory is in PATH so bare binary names resolve at exec time.
135+
/// Called once during `find_rtk_binary` init (single writer via OnceCell).
136+
fn ensure_dir_in_path(dir: &std::path::Path) {
137+
let dir_str = dir.to_string_lossy().to_string();
138+
if let Ok(path) = std::env::var("PATH")
139+
&& !path.split(':').any(|p| p == dir_str)
140+
{
141+
// SAFETY: called once during OnceCell init; no concurrent writers.
142+
unsafe {
143+
std::env::set_var("PATH", format!("{}:{}", dir_str, path));
144+
}
145+
}
146+
}
147+
134148
/// Find the RTK binary path (async, cached).
135149
///
136150
/// Checks in order:
@@ -154,14 +168,16 @@ async fn find_rtk_binary() -> Option<String> {
154168
let bundled_path = exe_dir.join(bin);
155169
if bundled_path.exists() && bundled_path.is_file() {
156170
tracing::info!("RTK binary found bundled at: {:?}", bundled_path);
157-
return Some(bundled_path.to_string_lossy().to_string());
171+
ensure_dir_in_path(exe_dir);
172+
return Some("rtk".to_string());
158173
}
159174

160175
// Check ./bin/rtk (bin subdirectory)
161176
let bin_path = exe_dir.join("bin").join(bin);
162177
if bin_path.exists() && bin_path.is_file() {
163178
tracing::info!("RTK binary found bundled at: {:?}", bin_path);
164-
return Some(bin_path.to_string_lossy().to_string());
179+
ensure_dir_in_path(&exe_dir.join("bin"));
180+
return Some("rtk".to_string());
165181
}
166182
}
167183

@@ -305,7 +321,10 @@ async fn download_and_install_rtk() -> Option<String> {
305321
}
306322
}
307323
tracing::info!(path = %dest.display(), bytes = data.len(), "RTK auto-download: installed");
308-
return Some(dest.to_string_lossy().to_string());
324+
if let Some(parent) = dest.parent() {
325+
ensure_dir_in_path(parent);
326+
}
327+
return Some("rtk".to_string());
309328
}
310329

311330
tracing::warn!("RTK auto-download: no writable install location found");

0 commit comments

Comments
 (0)