Test auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch failing

Resolved 💬 2 comments Opened Oct 21, 2025 by frextrite Closed Oct 21, 2025

What version of Codex is running?

latest HEAD commit on main 42d5c35020fb06f17578f2e5a98d21e5ef81427f

What subscription do you have?

N/A

Which model were you using?

_No response_

What platform is your computer?

Darwin 25.0.0 arm64 arm

What issue are you seeing?

auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch test-case failure when running cargo test -p codex-core --lib. Following is the output with RUST_BACKTRACE=1:

failures:

---- auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch stdout ----

thread 'auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch' panicked at core/src/auth.rs:761:14:
expected workspace mismatch to error: ()
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/panicking.rs:75:14
   2: core::result::unwrap_failed
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/result.rs:1765:5
   3: core::result::Result<T,E>::expect_err
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:1230:22
   4: codex_core::auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch::{{closure}}
             at ./src/auth.rs:761:14
   5: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:133:9
   6: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:133:9
   7: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:742:70
   8: tokio::task::coop::with_budget
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/task/coop/mod.rs:167:5
   9: tokio::task::coop::budget
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/task/coop/mod.rs:133:5
  10: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:742:25
  11: tokio::runtime::scheduler::current_thread::Context::enter
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:432:19
  12: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:741:44
  13: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:829:68
  14: tokio::runtime::context::scoped::Scoped<T>::set
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/context/scoped.rs:40:9
  15: tokio::runtime::context::set_scheduler::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/context.rs:176:38
  16: std::thread::local::LocalKey<T>::try_with
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:315:12
  17: std::thread::local::LocalKey<T>::with
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:279:20
  18: tokio::runtime::context::set_scheduler
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/context.rs:176:17
  19: tokio::runtime::scheduler::current_thread::CoreGuard::enter
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:829:27
  20: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:729:24
  21: tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:200:33
  22: tokio::runtime::context::runtime::enter_runtime
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/context/runtime.rs:65:16
  23: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/scheduler/current_thread/mod.rs:188:9
  24: tokio::runtime::runtime::Runtime::block_on_inner
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/runtime.rs:356:52
  25: tokio::runtime::runtime::Runtime::block_on
             at /Users/amolgrover/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.47.1/src/runtime/runtime.rs:330:18
  26: codex_core::auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch
             at ./src/auth.rs:766:10
  27: codex_core::auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch::{{closure}}
             at ./src/auth.rs:745:74
  28: core::ops::function::FnOnce::call_once
             at /Users/amolgrover/.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:253:5
  29: core::ops::function::FnOnce::call_once
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/ops/function.rs:253:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    auth::tests::enforce_login_restrictions_logs_out_for_workspace_mismatch

test result: FAILED. 378 passed; 1 failed; 4 ignored; 0 measured; 0 filtered out; finished in 12.51s

error: test failed, to rerun pass `-p codex-core --lib`

What steps can reproduce the bug?

cargo test -p codex-core --lib

What is the expected behavior?

All tests should succeed

Additional information

_No response_

View original on GitHub ↗

2 Comments

frextrite · 10 months ago

Isolating and running this test individually succeeds.

If however, it's _not_ run in isolation, load_auth inside enforce_login_restrictions returns an auth object with auth.mode set as ApiKey, which results in the conditional at L265 to succeed and return OK(()) instead of an Error.

Further, it appears that enforce_login_restrictions_blocks_env_api_key_when_chatgpt_required test-case is setting the CODEX_API_KEY env variable. This causes load_auth to read this env var and setup API key based auth which isn't expected (?) for this test scenario. Commenting out enforce_login_restrictions_blocks_env_api_key_when_chatgpt_required makes the original test succeed.

frextrite · 10 months ago

Adding #[parallel(codex_api_key)] attribute fixes it (quoting from serial_test docs, _"Tests with neither attribute may run at any time and no guarantees are made about their timing!"_), though I lack a broader context to determine if this attribute is also required for other tests. From what I understand, other tests that call enforce_login_restrictions _should_ also be annotated with this same attribute?

diff --git a/codex-rs/core/src/auth.rs b/codex-rs/core/src/auth.rs
index 92074c66..bc929f6a 100644
--- a/codex-rs/core/src/auth.rs
+++ b/codex-rs/core/src/auth.rs
@@ -485,6 +485,7 @@ mod tests {
     use pretty_assertions::assert_eq;
     use serde::Serialize;
     use serde_json::json;
+    use serial_test::parallel;
     use tempfile::tempdir;
 
     #[tokio::test]
@@ -742,6 +743,7 @@ mod tests {
     }
 
     #[tokio::test]
+    #[parallel(codex_api_key)]
     async fn enforce_login_restrictions_logs_out_for_workspace_mismatch() {
         let codex_home = tempdir().unwrap();
         let _jwt = write_auth_file(