Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Fix CI timeout in mock-stub PATH lookup (#654)
Maximilian Roos0d258be533b2
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 9caa2375c..2dcd2ad18 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -1806,6 +1806,9 @@ impl TestRepo {/// caller's PATH instead of a hardcoded minimal list.pub fn configure_mock_commands(&self, cmd: &mut Command) {if let Some(mock_bin) = &self.mock_bin_path {+ // Tell mock-stub where to find config files directly, avoiding PATH search+ cmd.env("MOCK_CONFIG_DIR", mock_bin);+// On Windows, env vars are case-insensitive but Rust stores them// case-sensitively. Find the actual PATH variable name to avoid// creating a duplicate with different case.diff --git a/tests/helpers/mock-stub/src/main.rs b/tests/helpers/mock-stub/src/main.rsindex 3d4af8603..4a63265d8 100644--- a/tests/helpers/mock-stub/src/main.rs+++ b/tests/helpers/mock-stub/src/main.rs@@ -1,7 +1,9 @@//! Config-driven mock executable for integration tests.//!//! Reads a JSON config file to determine responses. When invoked as `gh`,-//! looks for `gh.json` in the same directory and responds based on config.+//! looks for `gh.json` and responds based on config.+//!+//! Config location: `MOCK_CONFIG_DIR` env var (set by test harness)//!//! Config format://! ```json@@ -30,6 +32,7 @@ use std::collections::HashMap;use std::env;use std::fs;use std::io::{self, Write};+use std::path::PathBuf;use std::process::exit;#[derive(Debug, Deserialize)]@@ -47,55 +50,24 @@ struct CommandResponse {exit_code: i32,}-/// Find the executable path, preserving symlinks.-///-/// When spawned via PATH lookup (e.g., `Command::new("gh")`), argv\[0\] has no-/// directory component. We look it up in PATH to find the symlink location,-/// which is critical for finding the config file (e.g., `gh.json`).-fn find_executable_path() -> std::path::PathBuf {+/// Get command name from argv\[0\].+fn command_name() -> String {let argv0 = env::args().next().expect("mock: no argv[0]");- let exe_path = std::path::Path::new(&argv0);-- // If argv[0] has a path component, use it directly- if exe_path.parent().is_some_and(|p| !p.as_os_str().is_empty()) {- return exe_path.to_path_buf();- }-- // argv[0] is just a name (e.g., "gh"), look it up in PATH- if let Some(path_var) = env::var_os("PATH") {- for dir in env::split_paths(&path_var) {- let candidate = dir.join(&argv0);- if candidate.exists() {- return candidate;- }- // On Windows, also check with .exe extension- #[cfg(windows)]- {- let candidate_exe = dir.join(format!("{}.exe", argv0));- if candidate_exe.exists() {- return candidate_exe;- }- }- }- }+ std::path::Path::new(&argv0)+ .file_stem()+ .expect("mock: argv[0] has no file stem")+ .to_string_lossy()+ .into_owned()+}- // Last resort: current_exe() (resolves symlinks, may break config lookup)- env::current_exe().expect("failed to get executable path")+fn config_dir() -> PathBuf {+ PathBuf::from(env::var_os("MOCK_CONFIG_DIR").expect("mock: MOCK_CONFIG_DIR not set"))}fn main() {- let exe_path = find_executable_path();- let exe_dir = exe_path- .parent()- .expect("mock: executable has no parent directory")- .to_path_buf();- let cmd_name = exe_path- .file_stem()- .expect("mock: executable has no file stem")- .to_string_lossy()- .into_owned();-- let config_path = exe_dir.join(format!("{}.json", cmd_name));+ let cmd_name = command_name();+ let config_dir = config_dir();+ let config_path = config_dir.join(format!("{}.json", cmd_name));let content = fs::read_to_string(&config_path).unwrap_or_else(|e| {eprintln!("mock: failed to read {}: {}", config_path.display(), e);@@ -130,7 +102,7 @@ fn main() {.unwrap_or(&default_response);if let Some(file) = &response.file {- let file_path = exe_dir.join(file);+ let file_path = config_dir.join(file);match fs::read_to_string(&file_path) {Ok(contents) => {print!("{}", contents);diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rsindex 7c2e9289c..af5abae9c 100644--- a/tests/integration_tests/merge.rs+++ b/tests/integration_tests/merge.rs@@ -1085,12 +1085,16 @@ command = "{llm_path_str}"// Merge with --yes to skip approval prompts for commandslet (path_var, path_with_bin) = make_path_with_mock_bin(&bin_dir);+ let bin_dir_str = bin_dir.to_string_lossy();snapshot_merge_with_env("readme_example_complex",&repo,&["main", "--yes"],Some(&feature_wt),- &[(&path_var, &path_with_bin)],+ &[+ (&path_var, &path_with_bin),+ ("MOCK_CONFIG_DIR", &bin_dir_str),+ ],);}