From 0b06038859b412cf35e7c8212c9c7261612c1f32 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Mon, 12 Oct 2026 10:54:03 +0200 Subject: [PATCH] test(core): serialize screen-file test with the TMPDIR-mutating test screen_file_contents_and_write occasionally failed with NotFound when run in parallel with screen_temp_file_keeps_non_utf8_path_bytes: that test sets TMPDIR to a short-lived directory via temp_env, and std::env::temp_dir() evaluated outside temp_env's lock could resolve into it. The temp-file section now runs under temp_env's lock with TMPDIR unset. 25 consecutive runs of the core lib tests pass. --- crates/ghostty-core/src/surface/binding.rs | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/crates/ghostty-core/src/surface/binding.rs b/crates/ghostty-core/src/surface/binding.rs index 754b982..2c15984 100644 --- a/crates/ghostty-core/src/surface/binding.rs +++ b/crates/ghostty-core/src/surface/binding.rs @@ -1286,20 +1286,30 @@ mod tests { .is_none() ); - let path = - write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain).unwrap(); - assert!(path.ends_with("screen.txt")); - let path = path.to_string_lossy().into_owned(); // test-only: ASCII temp path - let read = std::fs::read_to_string(&path).unwrap(); - assert_eq!(read, s); - #[cfg(unix)] - { - let mode = std::os::unix::fs::PermissionsExt::mode( - &std::fs::metadata(&path).unwrap().permissions(), - ); - assert_eq!(mode & 0o777, 0o600); - } - let _ = std::fs::remove_dir_all(std::path::Path::new(&path).parent().unwrap()); + // Another test in this binary changes TMPDIR via temp_env, so the + // whole temp-file section runs under temp_env's lock with TMPDIR + // unset (std::env::temp_dir() then cannot point into that test's + // short-lived directory). + temp_env::with_var_unset("TMPDIR", || { + let own_tmp = std::env::temp_dir() + .join(format!("ghostty-screen-file-test-{}", std::process::id())); + std::fs::create_dir_all(&own_tmp).unwrap(); + let path = temp_env::with_var("TMPDIR", Some(&own_tmp), || { + write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain) + .unwrap() + }); + assert!(path.ends_with("screen.txt")); + let read = std::fs::read_to_string(&path).unwrap(); + assert_eq!(read, s); + #[cfg(unix)] + { + let mode = std::os::unix::fs::PermissionsExt::mode( + &std::fs::metadata(&path).unwrap().permissions(), + ); + assert_eq!(mode & 0o777, 0o600); + } + let _ = std::fs::remove_dir_all(&own_tmp); + }); } #[cfg(unix)]