From 8f2bc5b958c7a8432ae0ac78fa0c279065c18791 Mon Sep 17 00:00:00 2001 From: Rahul Thathoo Date: Sun, 10 May 2026 10:26:51 -0700 Subject: [PATCH] fix API key auth setup in rate limit tests --- .../app-server/tests/suite/v2/rate_limits.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/codex-rs/app-server/tests/suite/v2/rate_limits.rs b/codex-rs/app-server/tests/suite/v2/rate_limits.rs index b15960c1e9..b5b46c81ec 100644 --- a/codex-rs/app-server/tests/suite/v2/rate_limits.rs +++ b/codex-rs/app-server/tests/suite/v2/rate_limits.rs @@ -3,6 +3,7 @@ use app_test_support::ChatGptAuthFixture; use app_test_support::McpProcess; use app_test_support::to_response; use app_test_support::write_chatgpt_auth; +use app_test_support::write_mock_responses_config_toml; use codex_app_server_protocol::AddCreditsNudgeCreditType; use codex_app_server_protocol::AddCreditsNudgeEmailStatus; use codex_app_server_protocol::GetAccountRateLimitsResponse; @@ -19,6 +20,7 @@ use codex_config::types::AuthCredentialsStoreMode; use codex_protocol::account::PlanType as AccountPlanType; use pretty_assertions::assert_eq; use serde_json::json; +use std::collections::BTreeMap; use std::path::Path; use tempfile::TempDir; use tokio::time::timeout; @@ -61,6 +63,17 @@ async fn get_account_rate_limits_requires_auth() -> Result<()> { #[tokio::test] async fn get_account_rate_limits_requires_chatgpt_auth() -> Result<()> { let codex_home = TempDir::new()?; + let model_server = MockServer::start().await; + write_mock_responses_config_toml( + codex_home.path(), + &model_server.uri(), + &BTreeMap::new(), + /* auto_compact_limit */ 1024, + /* requires_openai_auth */ Some(true), + "mock_provider", + "compact", + )?; + mock_valid_api_key(&model_server).await; let mut mcp = McpProcess::new(codex_home.path()).await?; timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??; @@ -266,6 +279,17 @@ async fn send_add_credits_nudge_email_requires_auth() -> Result<()> { #[tokio::test] async fn send_add_credits_nudge_email_requires_chatgpt_auth() -> Result<()> { let codex_home = TempDir::new()?; + let model_server = MockServer::start().await; + write_mock_responses_config_toml( + codex_home.path(), + &model_server.uri(), + &BTreeMap::new(), + /* auto_compact_limit */ 1024, + /* requires_openai_auth */ Some(true), + "mock_provider", + "compact", + )?; + mock_valid_api_key(&model_server).await; let mut mcp = McpProcess::new(codex_home.path()).await?; timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??; @@ -450,6 +474,17 @@ async fn login_with_api_key(mcp: &mut McpProcess, api_key: &str) -> Result<()> { Ok(()) } +async fn mock_valid_api_key(server: &MockServer) { + Mock::given(method("GET")) + .and(path("/v1/models")) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({ + "models": [] + }))) + .expect(1) + .mount(server) + .await; +} + fn write_chatgpt_base_url(codex_home: &Path, base_url: &str) -> std::io::Result<()> { let config_toml = codex_home.join("config.toml"); std::fs::write(config_toml, format!("chatgpt_base_url = \"{base_url}\"\n"))