Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(test): use marker file for reliable fish wrapper test (#775)

worktrunk-bot4ba21ed9dd4a
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index faf1e557d..74e1b0297 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -2127,17 +2127,26 @@ approved-commands = ["echo 'bash background'"]
let init = shell::ShellInit::with_prefix(shell::Shell::Fish, "wt".to_string());
let wrapper_content = init.generate_fish_wrapper().unwrap();
- // Script that clears PATH so wt isn't found, then calls wt
+ // Create a marker file path to prove the script completed (didn't infinite loop)
+ let marker_file = repo.root_path().join(".test-completed-marker");
+
+ // Script that clears PATH so wt isn't found, then calls wt.
+ // The marker file is written AFTER the wt call to prove we didn't infinite loop.
+ // We capture the exit status before writing the marker so it's preserved.
let script = format!(
r#"
# Clear PATH to ensure wt is not found
set -x PATH /usr/bin /bin
set -x CLICOLOR_FORCE 1
- {}
+ {wrapper_content}
wt --version
- echo "exit_code: $status"
+ set -l wt_exit_status $status
+ # Write marker file to prove script completed (didn't infinite loop)
+ echo $wt_exit_status > {marker_file}
+ exit $wt_exit_status
"#,
- wrapper_content
+ wrapper_content = wrapper_content,
+ marker_file = marker_file.display()
);
let final_script = format!("begin\n{}\nend 2>&1", script);
@@ -2148,36 +2157,42 @@ approved-commands = ["echo 'bash background'"]
let (combined, exit_code) =
exec_in_pty_interactive(shell, &final_script, repo.root_path(), &env_vars, &[]);
- let output = ShellOutput {
- combined,
- exit_code,
- };
-
- // Should NOT show signs of infinite recursion (stack overflow, repeated function calls)
- // One occurrence of "in function 'wt'" is normal (fish's error trace).
- // Infinite recursion would show this MANY times.
- let function_call_count = output.combined.matches("in function 'wt'").count();
+ // PRIMARY CHECK: The marker file must exist, proving the script completed
+ // (didn't get stuck in an infinite loop). This is reliable even when PTY
+ // output capture fails on macOS.
assert!(
- function_call_count <= 1,
- "Fish wrapper should not infinite loop (found {} recursive calls).\nOutput:\n{}",
- function_call_count,
- output.combined
+ marker_file.exists(),
+ "Fish wrapper infinite looped (marker file not created).\n\
+ Exit code: {}\nOutput:\n{}",
+ exit_code,
+ combined
);
- // Should return exit code 127 (command not found)
- assert!(
- output.combined.contains("exit_code: 127"),
- "Fish wrapper should return exit code 127 when binary is missing.\nOutput:\n{}",
- output.combined
- );
+ // Read the exit status from the marker file. We use this rather than the PTY's
+ // exit_code because PTY layer behavior can differ from the shell's $status.
+ let marker_content = fs::read_to_string(&marker_file).unwrap_or_default();
+ let marker_exit_code: i32 = marker_content.trim().parse().unwrap_or(-1);
- // Should show fish's error message about unknown command
- assert!(
- output.combined.contains("Unknown command")
- || output.combined.contains("command not found"),
- "Fish wrapper should show error when binary is missing.\nOutput:\n{}",
- output.combined
+ // Verify exit code 127 (command not found)
+ assert_eq!(
+ marker_exit_code, 127,
+ "Fish wrapper should return exit code 127 when binary is missing.\n\
+ Marker file content: {:?}\nPTY exit code: {}\nOutput:\n{}",
+ marker_content, exit_code, combined
);
+
+ // SECONDARY CHECK: When output is available, verify no infinite recursion signs.
+ // One occurrence of "in function 'wt'" is normal (fish's error trace).
+ // Infinite recursion would show this MANY times.
+ if !combined.is_empty() {
+ let function_call_count = combined.matches("in function 'wt'").count();
+ assert!(
+ function_call_count <= 1,
+ "Fish wrapper shows signs of infinite loop ({} recursive calls).\nOutput:\n{}",
+ function_call_count,
+ combined
+ );
+ }
}
// ========================================================================