Skip to content

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

Fix: Remove leftover pending snapshot file

Maximilian Roos164ffc19ead2
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 99bb09307..088249ac7 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -906,6 +906,25 @@ pub fn wait_for_file_count(
);
}
+/// Wait for a file to have non-empty content, polling with exponential backoff.
+/// Use when a background process creates a file but may not have finished writing.
+pub fn wait_for_file_content(path: &Path, timeout: std::time::Duration) {
+ let start = std::time::Instant::now();
+ let mut attempt = 0;
+ while start.elapsed() < timeout {
+ if std::fs::metadata(path).is_ok_and(|m| m.len() > 0) {
+ return;
+ }
+ exponential_sleep(attempt);
+ attempt += 1;
+ }
+ panic!(
+ "File remained empty within {:?}: {}",
+ timeout,
+ path.display()
+ );
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/tests/integration_tests/.post_start_commands.rs.pending-snap b/tests/integration_tests/.post_start_commands.rs.pending-snap
deleted file mode 100644
index 38da46190..000000000
--- a/tests/integration_tests/.post_start_commands.rs.pending-snap
+++ /dev/null
@@ -1,29 +0,0 @@
-{"run_id":"1764011909-35386000","line":673,"new":{"module_name":"integration__integration_tests__post_start_commands","snapshot_name":"post_start_complex_shell_commands","metadata":{"source":"tests/integration_tests/post_start_commands.rs","assertion_line":673,"expression":"contents"},"snapshot":""},"old":{"module_name":"integration__integration_tests__post_start_commands","metadata":{},"snapshot":"line2"}}
-{"run_id":"1764011909-35386000","line":479,"new":null,"old":null}
-{"run_id":"1764011909-35386000","line":720,"new":null,"old":null}
-{"run_id":"1764011920-591405000","line":673,"new":null,"old":null}
-{"run_id":"1764011928-675839000","line":778,"new":null,"old":null}
-{"run_id":"1764011928-675839000","line":673,"new":{"module_name":"integration__integration_tests__post_start_commands","snapshot_name":"post_start_complex_shell_commands","metadata":{"source":"tests/integration_tests/post_start_commands.rs","assertion_line":673,"expression":"contents"},"snapshot":""},"old":{"module_name":"integration__integration_tests__post_start_commands","metadata":{},"snapshot":"line2"}}
-{"run_id":"1764011928-675839000","line":479,"new":{"module_name":"integration__integration_tests__post_start_commands","snapshot_name":"post_start_log_file_captures_output","metadata":{"source":"tests/integration_tests/post_start_commands.rs","assertion_line":479,"expression":"log_contents"},"snapshot":""},"old":{"module_name":"integration__integration_tests__post_start_commands","metadata":{},"snapshot":"stdout output\nstderr output"}}
-{"run_id":"1764011928-675839000","line":720,"new":null,"old":null}
-{"run_id":"1764011942-996292000","line":479,"new":null,"old":null}
-{"run_id":"1764011959-17122000","line":778,"new":null,"old":null}
-{"run_id":"1764011959-17122000","line":673,"new":null,"old":null}
-{"run_id":"1764011959-17122000","line":479,"new":null,"old":null}
-{"run_id":"1764011959-17122000","line":720,"new":null,"old":null}
-{"run_id":"1764011975-846206000","line":778,"new":null,"old":null}
-{"run_id":"1764011975-846206000","line":673,"new":null,"old":null}
-{"run_id":"1764011975-846206000","line":479,"new":null,"old":null}
-{"run_id":"1764011975-846206000","line":720,"new":null,"old":null}
-{"run_id":"1764011978-729122000","line":673,"new":null,"old":null}
-{"run_id":"1764011978-729122000","line":778,"new":null,"old":null}
-{"run_id":"1764011978-729122000","line":479,"new":null,"old":null}
-{"run_id":"1764011978-729122000","line":720,"new":null,"old":null}
-{"run_id":"1764011982-442283000","line":673,"new":null,"old":null}
-{"run_id":"1764011982-442283000","line":778,"new":null,"old":null}
-{"run_id":"1764011982-442283000","line":479,"new":null,"old":null}
-{"run_id":"1764011982-442283000","line":720,"new":null,"old":null}
-{"run_id":"1764012167-354610000","line":623,"new":null,"old":null}
-{"run_id":"1764012167-354610000","line":728,"new":null,"old":null}
-{"run_id":"1764012167-354610000","line":429,"new":null,"old":null}
-{"run_id":"1764012167-354610000","line":670,"new":null,"old":null}
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 8481ea362..cdb69d65f 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -1,6 +1,6 @@
use crate::common::{
TestRepo, make_snapshot_cmd, resolve_git_common_dir, setup_snapshot_settings, wait_for_file,
- wait_for_file_count,
+ wait_for_file_content, wait_for_file_count,
};
use insta::assert_snapshot;
use insta_cmd::assert_cmd_snapshot;
@@ -402,11 +402,11 @@ approved-commands = ["echo 'stdout output' && echo 'stderr output' >&2"]
&["--create", "feature"],
);
- // Wait for log directory to be created
+ // Wait for log file to be created (not just the directory)
let worktree_path = repo.root_path().parent().unwrap().join("test-repo.feature");
let git_common_dir = resolve_git_common_dir(&worktree_path);
let log_dir = git_common_dir.join("wt-logs");
- wait_for_file(log_dir.as_path(), Duration::from_secs(5));
+ wait_for_file_count(&log_dir, "log", 1, Duration::from_secs(5));
// Find the log file
let log_files: Vec<_> = fs::read_dir(&log_dir)
@@ -423,7 +423,11 @@ approved-commands = ["echo 'stdout output' && echo 'stderr output' >&2"]
log_files
);
- let log_contents = fs::read_to_string(&log_files[0]).unwrap();
+ // Wait for content to be written (background command might still be writing)
+ let log_file = &log_files[0];
+ wait_for_file_content(log_file, Duration::from_secs(5));
+
+ let log_contents = fs::read_to_string(log_file).unwrap();
// Verify both stdout and stderr were captured
assert_snapshot!(log_contents, @r"