From 04ec9ef8af6f3e8d112b073deb8b5f25c056e6ac Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 31 Mar 2026 14:44:54 -0700 Subject: [PATCH] Fix Windows external bearer refresh test (#16366) ## Why https://github.com/openai/codex/pull/16287 introduced a change to `codex-rs/login/src/auth/auth_tests.rs` that uses a PowerShell helper to read the next token from `tokens.txt` and rewrite the remainder back to disk. On Windows, `Get-Content` can return a scalar when the file has only one remaining line, so `$lines[0]` reads the first character instead of the full token. That breaks the external bearer refresh test once the token list is nearly exhausted. https://github.com/openai/codex/pull/16288 introduced similar changes to `codex-rs/core/src/models_manager/manager_tests.rs` and `codex-rs/core/tests/suite/client.rs`. These went unnoticed because the failures showed up when the test was run via Cargo on Windows, but not in our Bazel harness. Figuring out that Cargo-vs-Bazel delta will happen in a follow-up PR. ## Verification On my Windows machine, I verified `cargo test` passes when run in `codex-rs/login` and `codex-rs/core`. Once this PR is merged, I will keep an eye on https://github.com/openai/codex/actions/workflows/rust-ci-full.yml to verify it goes green. ## What changed - Wrap `Get-Content -Path tokens.txt` in `@(...)` so the script always gets array semantics before counting, indexing, and rewriting the remaining lines. --- codex-rs/core/src/models_manager/manager_tests.rs | 2 +- codex-rs/core/tests/suite/client.rs | 2 +- codex-rs/login/src/auth/auth_tests.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/models_manager/manager_tests.rs b/codex-rs/core/src/models_manager/manager_tests.rs index 3c9add309..1226f454c 100644 --- a/codex-rs/core/src/models_manager/manager_tests.rs +++ b/codex-rs/core/src/models_manager/manager_tests.rs @@ -145,7 +145,7 @@ mv tokens.next tokens.txt let script_path = tempdir.path().join("print-token.ps1"); std::fs::write( &script_path, - r#"$lines = Get-Content -Path tokens.txt + 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 diff --git a/codex-rs/core/tests/suite/client.rs b/codex-rs/core/tests/suite/client.rs index c0cbe445c..fc80e6d5a 100644 --- a/codex-rs/core/tests/suite/client.rs +++ b/codex-rs/core/tests/suite/client.rs @@ -190,7 +190,7 @@ mv tokens.next tokens.txt let script_path = tempdir.path().join("print-token.ps1"); std::fs::write( &script_path, - r#"$lines = Get-Content -Path tokens.txt + 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 diff --git a/codex-rs/login/src/auth/auth_tests.rs b/codex-rs/login/src/auth/auth_tests.rs index 3e230ca70..c781a2edc 100644 --- a/codex-rs/login/src/auth/auth_tests.rs +++ b/codex-rs/login/src/auth/auth_tests.rs @@ -366,7 +366,7 @@ mv tokens.next tokens.txt let script_path = tempdir.path().join("print-token.ps1"); std::fs::write( &script_path, - r#"$lines = Get-Content -Path tokens.txt + 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