diff --git a/codex-rs/shell-command/src/command_safety/is_safe_command.rs b/codex-rs/shell-command/src/command_safety/is_safe_command.rs index 940b59526d..dfba1ea7bd 100644 --- a/codex-rs/shell-command/src/command_safety/is_safe_command.rs +++ b/codex-rs/shell-command/src/command_safety/is_safe_command.rs @@ -617,11 +617,13 @@ mod tests { #[cfg(windows)] #[test] fn windows_powershell_full_path_is_safe() { - let powershell = crate::command_safety::trusted_windows_powershell_invocation_path() - .expect("Windows PowerShell must exist at the authoritative System known folder"); - let powershell = powershell - .to_str() - .expect("the Windows System known folder must be valid UTF-8"); + let Some(powershell) = crate::command_safety::trusted_windows_powershell_invocation_path() + else { + panic!("Windows PowerShell must exist at the authoritative System known folder"); + }; + let Some(powershell) = powershell.to_str() else { + panic!("the Windows System known folder must be valid UTF-8"); + }; assert!(is_known_safe_command(&vec_str(&[ powershell, diff --git a/codex-rs/shell-command/src/command_safety/powershell_parser.rs b/codex-rs/shell-command/src/command_safety/powershell_parser.rs index d1410fadea..7ddf8ee688 100644 --- a/codex-rs/shell-command/src/command_safety/powershell_parser.rs +++ b/codex-rs/shell-command/src/command_safety/powershell_parser.rs @@ -460,11 +460,12 @@ mod tests { #[test] fn production_resolver_handles_multiple_windows_powershell_requests() { - let powershell = trusted_windows_powershell_invocation_path() - .expect("Windows PowerShell must exist at the authoritative System known folder"); - let powershell = powershell - .to_str() - .expect("the Windows System known folder must be valid UTF-8"); + let Some(powershell) = trusted_windows_powershell_invocation_path() else { + panic!("Windows PowerShell must exist at the authoritative System known folder"); + }; + let Some(powershell) = powershell.to_str() else { + panic!("the Windows System known folder must be valid UTF-8"); + }; let first = try_parse_powershell_ast_commands(powershell, "Get-Content 'foo bar'") .map(PowershellParseOutcome::Commands) @@ -498,9 +499,9 @@ mod tests { ); return; }; - let pwsh = pwsh - .to_str() - .expect("the Program Files known folder must be valid UTF-8"); + let Some(pwsh) = pwsh.to_str() else { + panic!("the Program Files known folder must be valid UTF-8"); + }; assert_eq!( try_parse_powershell_ast_commands(pwsh, "pwd && ls"), @@ -509,14 +510,16 @@ mod tests { } fn trusted_windows_powershell_parser() -> PathBuf { - let invocation_path = trusted_windows_powershell_invocation_path() - .expect("Windows PowerShell must exist at the authoritative System known folder"); - trusted_powershell_parser_executable( - invocation_path - .to_str() - .expect("the Windows System known folder must be valid UTF-8"), - ) - .expect("the production trust resolver must accept Windows PowerShell") + let Some(invocation_path) = trusted_windows_powershell_invocation_path() else { + panic!("Windows PowerShell must exist at the authoritative System known folder"); + }; + let Some(invocation_path_str) = invocation_path.to_str() else { + panic!("the Windows System known folder must be valid UTF-8"); + }; + let Some(parser) = trusted_powershell_parser_executable(invocation_path_str) else { + panic!("the production trust resolver must accept Windows PowerShell"); + }; + parser } #[test] diff --git a/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs b/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs index d3ef7ff763..049f4e13fd 100644 --- a/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs +++ b/codex-rs/shell-command/src/command_safety/windows_safe_commands.rs @@ -222,19 +222,22 @@ mod tests { use std::sync::LazyLock; static WINDOWS_POWERSHELL_EXE: LazyLock = LazyLock::new(|| { - crate::command_safety::trusted_windows_powershell_invocation_path() - .expect("Windows PowerShell must exist at the authoritative System known folder") - .to_str() - .expect("the Windows System known folder must be valid UTF-8") - .to_string() + let Some(path) = crate::command_safety::trusted_windows_powershell_invocation_path() else { + panic!("Windows PowerShell must exist at the authoritative System known folder"); + }; + let Some(path) = path.to_str() else { + panic!("the Windows System known folder must be valid UTF-8"); + }; + path.to_string() }); fn installed_pwsh() -> Option<&'static str> { static STANDARD_PWSH_EXE: LazyLock> = LazyLock::new(|| { crate::command_safety::trusted_standard_pwsh_invocation_path().map(|path| { - path.to_str() - .expect("the Program Files known folder must be valid UTF-8") - .to_string() + let Some(path) = path.to_str() else { + panic!("the Program Files known folder must be valid UTF-8"); + }; + path.to_string() }) }); STANDARD_PWSH_EXE.as_deref()