From 4007c4c1ec23bf8497d06220a1290c14f06d823a Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Tue, 5 May 2026 04:26:53 +0300 Subject: [PATCH] codex: fix lenient enum CI fallout Address clippy and compile failures from wrapping config enums in Lenient. Co-authored-by: Codex --- .../app-server/tests/suite/v2/turn_start.rs | 6 +++++- codex-rs/config/src/config_toml.rs | 18 ++++++------------ codex-rs/config/src/profile_toml.rs | 12 ++++-------- codex-rs/core/src/config/config_tests.rs | 5 ++++- codex-rs/core/src/config/mod.rs | 12 +++++------- codex-rs/core/src/session/config_lock.rs | 2 +- .../core/tests/suite/personality_migration.rs | 2 +- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rs index 3c5bbd3b61..c7f6829e34 100644 --- a/codex-rs/app-server/tests/suite/v2/turn_start.rs +++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs @@ -50,6 +50,7 @@ use codex_app_server_protocol::TurnStartedNotification; use codex_app_server_protocol::TurnStatus; use codex_app_server_protocol::UserInput as V2UserInput; use codex_app_server_protocol::WarningNotification; +use codex_config::Lenient; use codex_config::config_toml::ConfigToml; use codex_core::personality_migration::PERSONALITY_MIGRATION_FILENAME; use codex_features::FEATURES; @@ -1323,7 +1324,10 @@ async fn turn_start_uses_migrated_pragmatic_personality_without_override_v2() -> let persisted_toml: ConfigToml = toml::from_str(&std::fs::read_to_string( codex_home.path().join("config.toml"), )?)?; - assert_eq!(persisted_toml.personality, Some(Personality::Pragmatic)); + assert_eq!( + persisted_toml.personality, + Some(Lenient::from(Personality::Pragmatic)) + ); assert!( codex_home .path() diff --git a/codex-rs/config/src/config_toml.rs b/codex-rs/config/src/config_toml.rs index acb7b34479..d9a4bba30f 100644 --- a/codex-rs/config/src/config_toml.rs +++ b/codex-rs/config/src/config_toml.rs @@ -510,27 +510,21 @@ impl From for UserSavedConfig { .collect(); Self { - approval_policy: config_toml - .approval_policy - .and_then(|value| value.into_valid()), - sandbox_mode: config_toml - .sandbox_mode - .and_then(|value| value.into_valid()), + approval_policy: config_toml.approval_policy.and_then(Lenient::into_valid), + sandbox_mode: config_toml.sandbox_mode.and_then(Lenient::into_valid), sandbox_settings: config_toml.sandbox_workspace_write.map(From::from), forced_chatgpt_workspace_id: config_toml.forced_chatgpt_workspace_id, forced_login_method: config_toml .forced_login_method - .and_then(|value| value.into_valid()), + .and_then(Lenient::into_valid), model: config_toml.model, model_reasoning_effort: config_toml .model_reasoning_effort - .and_then(|value| value.into_valid()), + .and_then(Lenient::into_valid), model_reasoning_summary: config_toml .model_reasoning_summary - .and_then(|value| value.into_valid()), - model_verbosity: config_toml - .model_verbosity - .and_then(|value| value.into_valid()), + .and_then(Lenient::into_valid), + model_verbosity: config_toml.model_verbosity.and_then(Lenient::into_valid), tools: config_toml.tools.map(From::from), profile: config_toml.profile, profiles, diff --git a/codex-rs/config/src/profile_toml.rs b/codex-rs/config/src/profile_toml.rs index e492fd4923..5359c20c2a 100644 --- a/codex-rs/config/src/profile_toml.rs +++ b/codex-rs/config/src/profile_toml.rs @@ -79,18 +79,14 @@ impl From for codex_app_server_protocol::Profile { Self { model: config_profile.model, model_provider: config_profile.model_provider, - approval_policy: config_profile - .approval_policy - .and_then(|value| value.into_valid()), + approval_policy: config_profile.approval_policy.and_then(Lenient::into_valid), model_reasoning_effort: config_profile .model_reasoning_effort - .and_then(|value| value.into_valid()), + .and_then(Lenient::into_valid), model_reasoning_summary: config_profile .model_reasoning_summary - .and_then(|value| value.into_valid()), - model_verbosity: config_profile - .model_verbosity - .and_then(|value| value.into_valid()), + .and_then(Lenient::into_valid), + model_verbosity: config_profile.model_verbosity.and_then(Lenient::into_valid), chatgpt_base_url: config_profile.chatgpt_base_url, } } diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index bf265ded49..65c4544ccf 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -3111,7 +3111,10 @@ async fn feedback_enabled_defaults_to_true() -> std::io::Result<()> { fn web_search_mode_defaults_to_none_if_unset() { let features = Features::with_defaults(); - assert_eq!(resolve_web_search_mode(None, &features), None); + assert_eq!( + resolve_web_search_mode(/*configured_mode*/ None, &features), + None + ); } #[test] diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 014dea6c66..90c465aed0 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -2532,14 +2532,12 @@ impl Config { value.into_valid_with_warning("approval_policy", &mut startup_warnings) }) { approval_policy + } else if active_project.is_trusted() { + AskForApproval::OnRequest + } else if active_project.is_untrusted() { + AskForApproval::UnlessTrusted } else { - if active_project.is_trusted() { - AskForApproval::OnRequest - } else if active_project.is_untrusted() { - AskForApproval::UnlessTrusted - } else { - AskForApproval::default() - } + AskForApproval::default() }; if !approval_policy_was_explicit && let Err(err) = constrained_approval_policy.can_set(&approval_policy) diff --git a/codex-rs/core/src/session/config_lock.rs b/codex-rs/core/src/session/config_lock.rs index eceaf9c0ed..62da0b3eae 100644 --- a/codex-rs/core/src/session/config_lock.rs +++ b/codex-rs/core/src/session/config_lock.rs @@ -149,7 +149,7 @@ mod tests { assert_eq!( lock.model_reasoning_effort .clone() - .and_then(|value| value.into_valid()), + .and_then(codex_config::Lenient::into_valid), sc.collaboration_mode.reasoning_effort() ); assert_eq!(lock.profile, None); diff --git a/codex-rs/core/tests/suite/personality_migration.rs b/codex-rs/core/tests/suite/personality_migration.rs index e4bc757f3c..76d2200aab 100644 --- a/codex-rs/core/tests/suite/personality_migration.rs +++ b/codex-rs/core/tests/suite/personality_migration.rs @@ -23,7 +23,7 @@ use tokio::io::AsyncWriteExt; const TEST_TIMESTAMP: &str = "2025-01-01T00-00-00"; fn valid_lenient(value: Option>) -> Option { - value.and_then(|value| value.into_valid()) + value.and_then(Lenient::into_valid) } async fn read_config_toml(codex_home: &Path) -> io::Result {