diff --git a/src/agent/agy/bridged_tests.rs b/src/agent/agy/bridged_tests.rs index 4038c87..cde0a6e 100644 --- a/src/agent/agy/bridged_tests.rs +++ b/src/agent/agy/bridged_tests.rs @@ -585,7 +585,6 @@ fn child_script(path: &Path, records_argv: Option<&Path>, marker: &str, value: & let exe = std::env::current_exe().expect("test binary"); #[cfg(unix)] { - use std::os::unix::fs::PermissionsExt; let before = records_argv .map(|argv| format!("printf '%s\\0' \"$@\" > '{}'", argv.display())) .unwrap_or_default(); @@ -594,8 +593,7 @@ fn child_script(path: &Path, records_argv: Option<&Path>, marker: &str, value: & value.display(), exe.display() ); - std::fs::write(path, body).expect("write the script"); - std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o755)).expect("runnable"); + crate::test_support::write_script(path, &body); } #[cfg(windows)] { diff --git a/src/agent/agy_tests.rs b/src/agent/agy_tests.rs index ab2341c..ef111d2 100644 --- a/src/agent/agy_tests.rs +++ b/src/agent/agy_tests.rs @@ -468,7 +468,6 @@ fn stand_in_agy(dir: &std::path::Path, lines: &[&str], stderr: &str, code: i32) } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let mut body = String::from("#!/bin/sh\n"); for line in lines { body.push_str(&format!("echo '{line}'\n")); @@ -478,9 +477,7 @@ fn stand_in_agy(dir: &std::path::Path, lines: &[&str], stderr: &str, code: i32) } body.push_str(&format!("exit {code}\n")); let path = dir.join("agy.sh"); - std::fs::write(&path, body).expect("write the stand-in agy"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &body); path } } @@ -524,6 +521,7 @@ fn a_whole_turn_reports_these_events_and_this_outcome() { 0, |b| b.set_models(&strings(&["gemini-3.8-flash-high"])), ); + // With the turn's end, so a turn that never started says why. assert_eq!( seen, vec![ @@ -540,7 +538,8 @@ fn a_whole_turn_reports_these_events_and_this_outcome() { cache_creation_tokens: 0, cache_read_tokens: 5, }, - ] + ], + "the turn ended: {result:?}" ); assert_eq!( result.expect("a result line"), diff --git a/src/agent/claude_code/tests.rs b/src/agent/claude_code/tests.rs index ec26096..b377256 100644 --- a/src/agent/claude_code/tests.rs +++ b/src/agent/claude_code/tests.rs @@ -225,17 +225,13 @@ fn a_loud_failing_agent(dir: &std::path::Path) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let path = dir.join("loud-agent.sh"); - std::fs::write( + crate::test_support::write_script( &path, "#!/bin/sh\ni=0\nwhile [ $i -lt 3000 ]; do echo \"stderr line $i padding \ padding padding padding padding padding padding\" >&2; i=$((i+1)); done\n\ echo 'token=hunter2-not-a-real-secret' >&2\nexit 3\n", - ) - .expect("write the fake agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + ); path } } @@ -350,7 +346,6 @@ fn a_cli_without_the_thinking_flag(dir: &std::path::Path) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let mut body = String::from( "#!/bin/bash\necho x >> \"$(dirname \"$0\")/starts.txt\"\n\ case \"$*\" in *--thinking-display*) \ @@ -361,9 +356,7 @@ fn a_cli_without_the_thinking_flag(dir: &std::path::Path) -> PathBuf { body.push_str(&format!("echo '{line}'\n")); } let path = dir.join("old-agent.sh"); - std::fs::write(&path, body).expect("write the stand-in agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &body); path } } @@ -444,7 +437,6 @@ pub(crate) fn stand_in_cli(dir: &std::path::Path, waits: bool) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let mut body = format!("#!/bin/bash\n{}echo '{}'\n", lists_the_tools(dir), LINES[0]); if waits { body.push_str("sleep 30\n"); @@ -453,9 +445,7 @@ pub(crate) fn stand_in_cli(dir: &std::path::Path, waits: bool) -> PathBuf { body.push_str(&format!("echo '{line}'\n")); } let path = dir.join(if waits { "slow-agent.sh" } else { "agent.sh" }); - std::fs::write(&path, body).expect("write the stand-in agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &body); path } } @@ -554,15 +544,12 @@ fn a_cli_whose_tool_server_never_starts(dir: &std::path::Path) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let mut body = String::from("#!/bin/sh\n"); for line in LINES { body.push_str(&format!("echo '{line}'\n")); } let path = dir.join("toolless-agent.sh"); - std::fs::write(&path, body).expect("write the stand-in agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &body); path } } @@ -608,18 +595,14 @@ fn a_cli_reporting_the_tool_server_failed(dir: &std::path::Path) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let path = dir.join("failed-server-agent.sh"); - std::fs::write( + crate::test_support::write_script( &path, - format!( + &format!( "#!/bin/sh\necho '{INIT}'\nsleep 5\n\ touch \"$(dirname \"$0\")/still-running.txt\"\necho '{RESULT}'\n" ), - ) - .expect("write the stand-in agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + ); path } } @@ -689,12 +672,8 @@ fn a_cli_that_ends_without_a_result(dir: &std::path::Path) -> PathBuf { } #[cfg(not(windows))] { - use std::os::unix::fs::PermissionsExt; let path = dir.join("cut-agent.sh"); - std::fs::write(&path, format!("#!/bin/sh\necho '{INIT}'\nexit 0\n")) - .expect("write the stand-in agent"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &format!("#!/bin/sh\necho '{INIT}'\nexit 0\n")); path } } diff --git a/src/agent/codex/tests.rs b/src/agent/codex/tests.rs index 5f6683e..f4b4870 100644 --- a/src/agent/codex/tests.rs +++ b/src/agent/codex/tests.rs @@ -622,7 +622,6 @@ fn child_script(path: &Path, records_argv: Option<&Path>, marker: &str, value: & let exe = std::env::current_exe().expect("test binary"); #[cfg(unix)] { - use std::os::unix::fs::PermissionsExt; let before = records_argv .map(|argv| format!("printf '%s\\0' \"$@\" > '{}'", argv.display())) .unwrap_or_default(); @@ -631,8 +630,7 @@ fn child_script(path: &Path, records_argv: Option<&Path>, marker: &str, value: & value.display(), exe.display() ); - std::fs::write(path, body).expect("write the script"); - std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o755)).expect("runnable"); + crate::test_support::write_script(path, &body); } #[cfg(windows)] { diff --git a/src/hooks/engine.rs b/src/hooks/engine.rs index 0ac0f1b..403c852 100644 --- a/src/hooks/engine.rs +++ b/src/hooks/engine.rs @@ -814,7 +814,6 @@ pub(crate) mod fake { } #[cfg(unix)] { - use std::os::unix::fs::PermissionsExt; let mut script = String::from("#!/bin/sh\nhere=\"$(dirname \"$0\")\"\n"); for (sub, reply) in replies { script.push_str(&format!( @@ -832,9 +831,7 @@ pub(crate) mod fake { } script.push_str("exit 0\n"); let path = dir.join("fake-engine.sh"); - std::fs::write(&path, script).expect("write the fake engine"); - std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)) - .expect("make it runnable"); + crate::test_support::write_script(&path, &script); path } } @@ -967,15 +964,13 @@ mod tests { let bin = { // The shared helper is `sh -c