From 1fa794954226f3ff5208d03f0ac6bf5a97eb0d2a Mon Sep 17 00:00:00 2001 From: mikewong23571 Date: Sun, 15 Mar 2026 01:03:08 +0800 Subject: [PATCH] test: fix Chrome temp-dir cleanup test on Windows (#766) --- cli/src/native/cdp/chrome.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cli/src/native/cdp/chrome.rs b/cli/src/native/cdp/chrome.rs index 6f05b80..3130a13 100644 --- a/cli/src/native/cdp/chrome.rs +++ b/cli/src/native/cdp/chrome.rs @@ -587,6 +587,28 @@ mod tests { use super::*; use crate::test_utils::EnvGuard; + #[cfg(unix)] + fn spawn_noop_child() -> Child { + Command::new("/bin/sh") + .args(["-c", "exit 0"]) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .unwrap() + } + + #[cfg(windows)] + fn spawn_noop_child() -> Child { + Command::new("cmd.exe") + .args(["/C", "exit 0"]) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .unwrap() + } + #[test] fn test_find_chrome_returns_some_on_host() { // This test only makes sense on systems with Chrome installed @@ -817,13 +839,7 @@ mod tests { // Simulate a ChromeProcess with a temp dir but a dummy child. // We can't actually spawn Chrome here, but we can verify the Drop // logic by creating a small helper process. - let child = Command::new("echo") - .arg("test") - .stdin(Stdio::null()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn() - .unwrap(); + let child = spawn_noop_child(); let _process = ChromeProcess { child, ws_url: String::new(),