Skip to content

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

Fix: Ensure post-start command output is flushed

Maximilian Roos354e2ea61cde
diff --git a/tests/integration_tests/.post_start_commands.rs.pending-snap b/tests/integration_tests/.post_start_commands.rs.pending-snap
index 8cf591ada..d7fa15196 100644
--- a/tests/integration_tests/.post_start_commands.rs.pending-snap
+++ b/tests/integration_tests/.post_start_commands.rs.pending-snap
@@ -13,3 +13,17 @@
{"run_id":"1764015452-863643000","line":625,"new":null,"old":null}
{"run_id":"1764015452-863643000","line":431,"new":null,"old":null}
{"run_id":"1764015452-863643000","line":672,"new":null,"old":null}
+{"run_id":"1764016037-744134000","line":677,"new":null,"old":null}
+{"run_id":"1764016053-461593000","line":735,"new":null,"old":null}
+{"run_id":"1764016053-461593000","line":630,"new":null,"old":null}
+{"run_id":"1764016053-461593000","line":431,"new":null,"old":null}
+{"run_id":"1764016053-461593000","line":677,"new":null,"old":null}
+{"run_id":"1764016195-594834000","line":735,"new":null,"old":null}
+{"run_id":"1764016195-594834000","line":630,"new":null,"old":null}
+{"run_id":"1764016195-594834000","line":431,"new":null,"old":null}
+{"run_id":"1764016195-594834000","line":677,"new":{"module_name":"integration__integration_tests__post_start_commands","snapshot_name":"post_start_multiline_commands_with_newlines","metadata":{"source":"tests/integration_tests/post_start_commands.rs","assertion_line":677,"expression":"contents"},"snapshot":"first line"},"old":{"module_name":"integration__integration_tests__post_start_commands","metadata":{},"snapshot":"first line\nsecond line\nthird line"}}
+{"run_id":"1764016208-474514000","line":677,"new":null,"old":null}
+{"run_id":"1764016239-571456000","line":735,"new":null,"old":null}
+{"run_id":"1764016239-571456000","line":630,"new":null,"old":null}
+{"run_id":"1764016239-571456000","line":431,"new":null,"old":null}
+{"run_id":"1764016239-571456000","line":677,"new":null,"old":null}
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index b1ce11b40..7aa6a2b90 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -1,8 +1,9 @@
-use crate::common::{TestRepo, setup_temp_snapshot_settings, wt_command};
+use crate::common::{TestRepo, setup_temp_snapshot_settings, wait_for_file, wt_command};
use insta_cmd::assert_cmd_snapshot;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
+use std::time::Duration;
/// Helper to create a bare repository test setup
struct BareRepoTest {
@@ -584,18 +585,10 @@ fn test_bare_repo_background_logs_location() {
);
}
- // Give background process time to create log file (file gets created immediately, content written later)
- std::thread::sleep(std::time::Duration::from_millis(500));
-
- // Verify log file was created in bare repo's wt-logs directory (not in worktree's .git/)
+ // Wait for background process to create log file (poll instead of fixed sleep)
// The key test is that the path is correct, not that content was written (background processes are flaky in tests)
let log_path = test.bare_repo_path().join("wt-logs/feature-remove.log");
- assert!(
- log_path.exists(),
- "Background removal log should be created in bare repo's wt-logs/ directory at {:?}.\nBare repo path: {:?}",
- log_path,
- test.bare_repo_path()
- );
+ wait_for_file(&log_path, Duration::from_secs(5));
// Verify it's NOT in the worktree's .git directory (which doesn't exist for linked worktrees)
let wrong_path = main_worktree.join(".git/wt-logs/feature-remove.log");
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index bba3e863c..4bb7e4e20 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -1,26 +1,11 @@
use crate::common::{
TestRepo, resolve_git_common_dir,
shell::{execute_shell_script, generate_init_code, path_export_syntax, wt_bin_dir},
+ wait_for_file, wait_for_file_content,
};
use rstest::rstest;
use std::fs;
-use std::thread;
-use std::time::{Duration, Instant};
-
-fn wait_for_file(path: &std::path::Path, timeout: Duration) {
- let start = Instant::now();
- while start.elapsed() < timeout {
- if path.exists() {
- return;
- }
- thread::sleep(Duration::from_millis(50));
- }
- panic!(
- "File was not created within {:?}: {}",
- timeout,
- path.display()
- );
-}
+use std::time::Duration;
/// Test that post-start background commands work with shell integration
#[rstest]
@@ -110,13 +95,10 @@ approved-commands = ["sleep 0.05 && echo 'Background task done' > bg_marker.txt"
log_files
);
- // Wait for background command to complete (allow plenty of margin on CI)
- wait_for_file(
- worktree_path.join("bg_marker.txt").as_path(),
- Duration::from_secs(1),
- );
-
+ // Wait for background command to complete AND flush content (allow plenty of margin on CI)
let marker_file = worktree_path.join("bg_marker.txt");
+ wait_for_file_content(marker_file.as_path(), Duration::from_secs(2));
+
let content = fs::read_to_string(&marker_file).unwrap();
assert!(
content.contains("Background task done"),
@@ -323,28 +305,14 @@ approved-commands = ["sleep 0.05 && echo 'Fish background done' > fish_bg.txt"]
output
);
- // Wait for background command (allow plenty of margin on CI)
- wait_for_file(
- repo.root_path()
- .parent()
- .unwrap()
- .join("test-repo.fish-bg-test")
- .join("fish_bg.txt")
- .as_path(),
- Duration::from_secs(1),
- );
-
- // Verify background command ran
+ // Wait for background command AND flush content (allow plenty of margin on CI)
let worktree_path = repo
.root_path()
.parent()
.unwrap()
.join("test-repo.fish-bg-test");
let marker_file = worktree_path.join("fish_bg.txt");
- assert!(
- marker_file.exists(),
- "Fish background command should have created fish_bg.txt"
- );
+ wait_for_file_content(marker_file.as_path(), Duration::from_secs(2));
let content = fs::read_to_string(&marker_file).unwrap();
assert!(
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 5966ba6be..966e723b8 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -668,10 +668,10 @@ approved-commands = ["""
&["--create", "feature"],
);
- // Wait for background command to create the file
+ // Wait for background command to create the file AND flush content
let worktree_path = repo.root_path().parent().unwrap().join("test-repo.feature");
let output_file = worktree_path.join("multiline.txt");
- wait_for_file(output_file.as_path(), Duration::from_secs(5));
+ wait_for_file_content(output_file.as_path(), Duration::from_secs(5));
let contents = fs::read_to_string(&output_file).unwrap();
assert_snapshot!(contents, @r"