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.
This commit is contained in:
ddidderr committed 2026-10-12 10:54:03 +02:00
1 parent af094276f8
commit daf5080453
1 file changed
+24 -14
+24 -14
View File
@@ -1286,20 +1286,30 @@ mod tests {
.is_none() .is_none()
); );
let path = // Another test in this binary changes TMPDIR via temp_env, so the
write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain).unwrap(); // whole temp-file section runs under temp_env's lock with TMPDIR
assert!(path.ends_with("screen.txt")); // unset (std::env::temp_dir() then cannot point into that test's
let path = path.to_string_lossy().into_owned(); // test-only: ASCII temp path // short-lived directory).
let read = std::fs::read_to_string(&path).unwrap(); temp_env::with_var_unset("TMPDIR", || {
assert_eq!(read, s); let own_tmp = std::env::temp_dir()
#[cfg(unix)] .join(format!("ghostty-screen-file-test-{}", std::process::id()));
{ std::fs::create_dir_all(&own_tmp).unwrap();
let mode = std::os::unix::fs::PermissionsExt::mode( let path = temp_env::with_var("TMPDIR", Some(&own_tmp), || {
&std::fs::metadata(&path).unwrap().permissions(), write_screen_temp_file(&s, WriteScreenLoc::Screen, WriteScreenFormat::Plain)
); .unwrap()
assert_eq!(mode & 0o777, 0o600); });
} assert!(path.ends_with("screen.txt"));
let _ = std::fs::remove_dir_all(std::path::Path::new(&path).parent().unwrap()); 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)] #[cfg(unix)]