From beb3978a3ba15c631d6844a967b05e0b68a3a196 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 2 Apr 2026 17:33:07 -0700 Subject: [PATCH] test: use cmd.exe for ProviderAuthScript on Windows (#16629) ## Why The Windows `ProviderAuthScript` test helpers do not need PowerShell. Running them through `cmd.exe` is enough to emit the next fixture token and rotate `tokens.txt`, and it avoids a PowerShell-specific dependency in these tests. ## What changed - Replaced the Windows `print-token.ps1` fixtures with `print-token.cmd` in `codex-rs/core/src/models_manager/manager_tests.rs` and `codex-rs/login/src/auth/auth_tests.rs`. - Switched the failing external-auth helper in `codex-rs/login/src/auth/auth_tests.rs` from `powershell.exe -Command 'exit 1'` to `cmd.exe /d /s /c 'exit /b 1'`. - Updated Windows timeout comments so they no longer call out PowerShell specifically. ## Verification - `cargo test -p codex-login` - `cargo test -p codex-core` (fails in unrelated `core/src/config/config_tests.rs` assertions in this checkout) --- .../core/src/models_manager/manager_tests.rs | 33 +++++++------ codex-rs/login/src/auth/auth_tests.rs | 46 +++++++++++-------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/codex-rs/core/src/models_manager/manager_tests.rs b/codex-rs/core/src/models_manager/manager_tests.rs index 6ab1c267b..48c01f198 100644 --- a/codex-rs/core/src/models_manager/manager_tests.rs +++ b/codex-rs/core/src/models_manager/manager_tests.rs @@ -112,10 +112,12 @@ impl ProviderAuthScript { fn new(tokens: &[&str]) -> std::io::Result { let tempdir = tempfile::tempdir()?; let tokens_file = tempdir.path().join("tokens.txt"); + // `cmd.exe`'s `set /p` treats LF-only input as one line, so use CRLF on Windows. + let token_line_ending = if cfg!(windows) { "\r\n" } else { "\n" }; let mut token_file_contents = String::new(); for token in tokens { token_file_contents.push_str(token); - token_file_contents.push('\n'); + token_file_contents.push_str(token_line_ending); } std::fs::write(&tokens_file, token_file_contents)?; @@ -142,23 +144,28 @@ mv tokens.next tokens.txt #[cfg(windows)] let (command, args) = { - let script_path = tempdir.path().join("print-token.ps1"); + let script_path = tempdir.path().join("print-token.cmd"); std::fs::write( &script_path, - r#"$lines = @(Get-Content -Path tokens.txt) -if ($lines.Count -eq 0) { exit 1 } -Write-Output $lines[0] -$lines | Select-Object -Skip 1 | Set-Content -Path tokens.txt + r#"@echo off +setlocal EnableExtensions DisableDelayedExpansion +set "first_line=" + ModelProviderAuthInfo { let timeout_ms = if cfg!(windows) { - // `powershell.exe` startup can be slow on loaded Windows CI workers + // Process startup can be slow on loaded Windows CI workers. 10_000 } else { 2_000 diff --git a/codex-rs/login/src/auth/auth_tests.rs b/codex-rs/login/src/auth/auth_tests.rs index 3ee877872..fb7da63e7 100644 --- a/codex-rs/login/src/auth/auth_tests.rs +++ b/codex-rs/login/src/auth/auth_tests.rs @@ -355,10 +355,12 @@ impl ProviderAuthScript { fn new(tokens: &[&str]) -> std::io::Result { let tempdir = tempfile::tempdir()?; let token_file = tempdir.path().join("tokens.txt"); + // `cmd.exe`'s `set /p` treats LF-only input as one line, so use CRLF on Windows. + let token_line_ending = if cfg!(windows) { "\r\n" } else { "\n" }; let mut token_file_contents = String::new(); for token in tokens { token_file_contents.push_str(token); - token_file_contents.push('\n'); + token_file_contents.push_str(token_line_ending); } std::fs::write(&token_file, token_file_contents)?; @@ -385,23 +387,28 @@ mv tokens.next tokens.txt #[cfg(windows)] let (command, args) = { - let script_path = tempdir.path().join("print-token.ps1"); + let script_path = tempdir.path().join("print-token.cmd"); std::fs::write( &script_path, - r#"$lines = @(Get-Content -Path tokens.txt) -if ($lines.Count -eq 0) { exit 1 } -Write-Output $lines[0] -$lines | Select-Object -Skip 1 | Set-Content -Path tokens.txt + r#"@echo off +setlocal EnableExtensions DisableDelayedExpansion +set "first_line=" +